You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for every i,j check if "X" is present return false or if reached m,n then return true else call for func for down(i+1,j) and right(i,j+1) and mark it as 1. Mark 0 after both func are called
call recursively for row+1. construct 3 bit arrays:column,diag 1 and diag2. for every call loop from c=0 to n and check if that index is occupied in the array.
for all empty cells try to fill no. from 1 to 9 and build a function canplace(), which checks if the no. can be placed or not. call recursively for j+1 until row end and then i+1
slow and fast ptrs; fast moves two steps and slow move one; if slow==fast then cycle is present; if we want find the start of the cycle, move the slow to head and move both ptrs one step, the point where the meet is the start==fast is the start of cycle
use an addition stack. Run a loop till n; In each iteration store the top in temp and transfer rest n-i elements to aux stack; Push the temp to bottom of current stack; Transfer the n-i elements from aux stack to curr stack
Implement two functions: reversal and place_at_bottom; reversal constantly calls itself and builds a reverse call stack, then call place_at_bottom with elements of this call stack; Place_at_bottom pushes the element at the bottom, else calls itself to build a call stack to put the element at bottom and then pushes the rest elements into the stack
create a pair of height and isBalanced. recursively call the func for left and right subtree. If (abs(hright-hleft))<=1 and left and right subtree then current subtree is balanced and height = max(left,right)+1
3 cases; 1. no children, then simply delete. 2. one child, then store the child in temp, delete the root and return temp; 2 children, then return inorder successor
Recursion. Create a class LL with node* head and node* tail. There will 4 major cases. root has: 1)no child: ll.head=ll.tail=root;2)only left child:call the recursive func with left child. ll.head=leftll.head and ll.tail=root;3)only right child: ll.head=root and ll.tail=rightll.tail; root has both the children: call function for both the children. ll.head = leftll.head, ll.tail=rightll.tail. In all the cases connect the root accordingly.
Implement through a queue. children of a node are always at 2i and 2i+1; heapify: replace the first element with last and then heapify the first element
create a heap and insert all the first elements of each array; remove the top element of the array and push a element from the same array from which the top element was removed. if array has no elements then push infinite
maintain two heaps, leftheap-a max heap and rightheap-a min heap. if there are any elements in the right queue and right.top() is smaller than current element then add into right queue else add in left queue. The difference b/w sizes of these should not be greater than 1, in such a case transfer the top element. when queried either print the avg, if size equal else print the top of the largest heap