
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

291 Views
Suppose we have a value n. We have to find all upside down numbers of length n. As we knot the upside down number is one that appears the same when flipped 180 degrees.So, if the input is like n = 2, then the output will be ['11', '69', '88', '96'].To solve this, we will follow these steps −Define a function middle() . This will take xif x is 0, thenreturn list of a blank stringif x is same as 1, thenreturn a new list of elements 0, 1, 8ret := a new listmid := middle(x − 2)for each m ... Read More

304 Views
Suppose we have a binary tree, we have to check whether all nodes in the tree have the same values or not.So, if the input is likethen the output will be TrueTo solve this, we will follow these steps −Define a function solve() . This will take root, and valif root is null, thenreturn Trueif val is not defined, thenval := value of rootreturn true when value of root is same as val and solve(left of root, val) and solve(right of root, val) are also trueLet us see the following implementation to get better understanding −Example Live Democlass TreeNode: def ... Read More

289 Views
Suppose we have a list of numbers nums (positive or negative), we have to check whether the number of occurrences of every value in the array is unique or not.So, if the input is like nums = [6, 4, 2, 9, 4, 2, 2, 9, 9, 9], then the output will be True, as there is 1 occurrence of 6, 2 occurrences of 4, 3 occurrences of 2, and 4 occurrences of 9. So all number of occurrences are unique.To solve this, we will follow these steps −num_counts := a new map where all values and number of occurrences of ... Read More

352 Views
Suppose we have a matrix called requested_trips where each row containing [start_x, end_x, num_passengers], and we also have a capacity value. Now each requested trip asks to pick up num_passengers passenger at start_x and drop them off at end_x. We also have a car with the capacity that is given, and start at position x = 0. We want to to pick up every passenger and can only move right side, we have to check whether we can pick up and drop off everyone.So, if the input is like trips = [[1, 25, 2], [3, 4, 3], [5, 12, 3]] ... Read More

144 Views
Suppose we have a list of numbers called nums and another value k, we have to find two nonoverlapping sublists in nums whose sum is k, and we have to find the sum of their lengths. When there are more than two possible sublists, we have to find the sum of the lengths of the two smallest sublists. If we cannot find the answer, return −1.So, if the input is like nums = [7, 10, −2, −1, 4, 3] k = 7, then the output will be 3, as we pick the sublists like [7] and [4, 3]. We did ... Read More

157 Views
Suppose we have two binary trees, we have to check whether they are exactly same in terms of their structures and values or not. We can say them as twin trees.So, if the input is likethen the output will be True for the first pair, false for the second pair and third pair as for second and third items are different and the structures are different respectively.To solve this, we will follow these steps −Define a method solve(), this will take two rootsif root0 is null and root1 is null, thenreturn Trueif root0 is null or root1 is null, thenreturn ... Read More

211 Views
Suppose we have a string s, we have to find the number of ways we can obtain a palindrome by trimming the left and right sides of s.So, if the input is like s = "momo", then the output will be 6, as You can get ["mom", "omo", "o", "o", "m", "m", "o")To solve this, we will follow these steps −Define a function expand() . This will take i, j, sc := 0while i >= 0 and j < size of s and s[i] is same as s[j], doi := i − 1, j := j + 1c := c ... Read More

280 Views
Suppose we have a binary tree and a list of strings moves consisting of "R"(Right), "L"(Left) and "U"(Up). Starting from root, we have to traverse the tree by performing each move in moves where: "R" indicates traverse to the right child. "L" indicates traverse to the left child. "U" indicates traverse to its parent.So, if the input is like["R", "R", "U", "L"], then the output will be 3To solve this, we will follow these steps −past := a new listfor each move in moves, doinsert root at the end of pastif move is same as "L", thenroot := left of ... Read More

932 Views
Suppose we have a binary tree containing some values, we have to find the sum of all values in the tree.So, if the input is likethen the output will be 14To solve this, we will follow these steps −Define a function recurse() . This will take nodeval := value of nodeif left of node is not null, thenval := val + recurse(left of node)if right of node is not−null, thenval := val + recurse(right of node)return valFrom the main method, do the following −if not root is non−zero, thenreturn 0return recurse(root)Let us see the following implementation to get better understanding ... Read More

237 Views
Suppose we have a 2D matrix there are few values like below −0 represents an empty cell.1 represents a wall.2 represents a person.Here a person can walk any of these four directions (up, down, left and right). We have to find a cell that is not wall such that it minimizes the total travel distance each person has to walk to and finally find the distance.So, if the input is like201010120022then the output will be 7 as the best meeting point is the bottom right corner.To solve this, we will follow these steps −twos := a new map, costs := ... Read More