
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 33676 Articles for Programming

934 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

379 Views
Suppose we have a binary tree, where every node's value is either a 0 or a 1. We have to find the same tree where every subtree not containing a 1 has been deleted. So if the tree is like −To solve this, we will follow these steps −Define a recursive method solve(), this will take the node. the method will be like −If node is null, then return nullleft of node := solve(left of node)right of node := solve(right of node)if left of node is null and right of node is also null and node value is 0, then ... Read More

238 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

225 Views
Suppose we have a 2D grid representing a maze where 0 is for empty space, and 1 is the wall. We will start at grid[0, 0], we have to find the minimum number of squares it would take to get to bottom right corner of the grid. If we cannot reach, return −1.So, if the input is like000100100then the output will be 5To solve this, we will follow these steps −R := row count of grid, C := column count of gridq := [0, 0, 1] when A[0, 0] is 1 otherwise a new listA[0, 0] := 1for each (r, ... Read More

144 Views
Suppose we have a column title of spreadsheet. We know that the spreadsheet column numbers are alphabetic. It starts from A, and after Z, it will AA, AB, to ZZ, then again AAA, AAB, to ZZZ and so on. So column 1 is A, column 27 is Z. Here we will see how to get the column letter if number of column is given. So if the column number is 80, then it will be CB. So we have to find the corresponding column title from the number. If the input is like 30, it will AD.Example Live Demo#include #include using ... Read More

216 Views
Suppose we have a positive integer value; we have to find its corresponding column title as appear in a spread sheet. So [1 : A], [2 : B], [26 : Z], [27 : AA], [28 : AB] etc.So, if the input is like 29, then the output will be AC.To solve this, we will follow these steps −while n is non-zero, do −n := n − 1res := res + n mod 26 + ASCII of 'A'n := n / 26reverse the array resreturn resLet us see the following implementation to get better understanding −Example Live Demo#include using namespace std; ... Read More

238 Views
Suppose we have a list of values called tasks where each different value represents a different task type, and we also have a non-negative integer k. Each task wants one minute to complete, but we must wait k minutes between doing two tasks of the same type. At any time, we can be doing a task or waiting. We have to find the smallest amount of time it takes to complete all the tasks.So, if the input is like nums = [2, 2, 2, 3, 3, 2], k = 1, then the output will be 7, as the optimal ordering ... Read More

396 Views
Suppose we have two values start and end, we have to find the minimum number of operations needed to convert start to end by using these operations −Decrement by 1Multiply by 2So, if the input is like start = 2, end = 7, then the output will be 3, as we can multiply 2 to get 4, then multiply 2 to get 8 and then subtract 1 to get 7.To solve this, we will follow these steps −ans := 0Do the following infinitely, doif end

291 Views
Suppose we have one binary tree. We have to check whether the tree is symmetric tree or not. A tree will be said to be symmetric if it is same when we take the mirror image of it. From these two trees, the first one is symmetric, but second one is not.To solve this, we will follow these steps.We will call following steps recursively. The function will be solve(root, root)if the node1 and node2 are empty, then return trueif either node1 or node2 is empty, then return falsereturn true when node1.val = node2.val and solve(node1.left, node2.right) and solve(node1.right, node2.left)Let us ... Read More

172 Views
Suppose we have two trees, we have to check whether we can transform first tree into second one by swapping any node's left and right subtrees any number of times.So, if the input is likethen the output will be TrueTo solve this, we will follow these steps −que1 := a queue with root0 initiallyque2 := a queue with root1 initiallywhile que1 and que2 are not empty, dotemp1 := a new list, temp2 := a new listvalues1 := a new list, values2 := a new listif que1 and que2 are containing different number of elements, thenreturn Falsefor i in range 0 ... Read More