Skip to content

Instantly share code, notes, and snippets.

@saumya0908
saumya0908 / FAQ
Last active January 4, 2022 10:35
Maximum Path Sum In Between Two Leaves Of Binary Tree
Q.1 If we get maximum sum from left-subtree and and right subtree, Should we include the root node also?
ANS: It is not compulsory to always include root node. For example: If root node is negative.
Q.2 For a binary tree, Would the value of maximum sum will always greater than 0.
ANS:NO, the value of maximum sum can also be negative.
Q.3 What faith will be build to find Maximum Path Sum In Between Two Leaves Of Binary Tree?
@saumya0908
saumya0908 / FAQ
Last active January 4, 2022 11:38
The K-th Lexicographical String Of All Happy Strings Of Length N
Q.1 Why to use stringBuilder in place of string?
ANS: Because it is much faster and consumes less memory.
Q.2 What will get updated , while iterating over the value of 'k' ?
ANS: total will get updated to spart (total=part)
previous calls will get updated to new calls.
Q.3 What will happen if new_call is 0 and prev_call is also '0'?
@saumya0908
saumya0908 / FAQ
Created January 3, 2022 08:16
Sum Of Subsequence Widths
Q.1 Why the brute force approach won't work for the constraint(length of array<=20000)?
ANS: The time-complexity for brute-force method will be O(n* 2^n). which will go beyond the array range for integers.
Q.2 What is the width for the array?
ANS: Width is the difference between the maximum and minimum element.
Q.3 How the sorting wont affect finding the width for subsequence?
@saumya0908
saumya0908 / FAQ
Last active January 3, 2022 12:02
Count Pairs With Xor In A Range
Q.1 List the possible combination for performing XOR operation.
ANS: 0 ^ 0 = 0
0 ^ 1 = 1
1 ^ 0 = 1
1 ^ 1 = 0
Q.2 What is the brute-force method "to count all pairs with XOR in a range"?
ANS: Firstly traverse the given array and generate all possible pairs from the given array and for each pair, check if bitwise XOR of the pair is less than or equal to 'high' and greater than or equal to 'low'.
@saumya0908
saumya0908 / FAQ
Last active January 3, 2022 11:33
Implement Trie
Q.1 What does the search() function do in a trie?
ANS: It searches for the given string ('key') in O(l) time complexity where 'l' is the length of the 'key'.
Q.2 What does the startsWith() function do in a trie?
ANS: It is somewhat similar to search() function. It searches for the string that starts with the given key ('prefix')
Q.3 What is the difference between search() and startsWith() function?
@saumya0908
saumya0908 / FAQ
Created December 30, 2021 09:00
Maximum Width Of Binary Tree
Q.1 Why we need to traverse level-order wise?
ANS: Because we are finding width at each level using its left-most and right-most node indexes.
Q.2 What is the role of queue in this?
ANS: In the queue we are putting the position of each node, along with the node, so we will use that position to find the width(i.e. length between left-most node and right-most node)
Q.3 How we will get the indexes of leftmost and rightmost node at each level?
@saumya0908
saumya0908 / FAQ
Last active January 3, 2022 09:55
All Nodes Distance K In Binary Tree
Q.1 Discuss the role of 'node-to-root path'.
ANS: The nodes present in 'node-to-root path' will print the nodes present " 'k' 'k-1' 'k-2' ..... 1, 0 levels down"
Q.2 How we are using print 'k' levels down function to print all the nodes at distance 'k' from a given 'node'?
ANS: We are finding the node-to-root path. Let the nodes present in node to root path are (node,node1, .....root) then we will use print 'k' levels down to print node ('k' ,'k-1',.... '0') levels down respectively.
Q.3 Why we are blocking the node while calling function print 'k' levels down?
@saumya0908
saumya0908 / FAQ
Last active January 3, 2022 09:35
Diagonal Order Sum Of A Binary Tree
Q.1 Why we are creating arraylist?
ANS: To store the sum of all nodes present at each diagonal level where the index of arraylist represent the diagonal level indexing of binary tree.
Q.2 What we will store in queue?
ANS: Queue will contain all the left child of elements added in arraylist.
Q.3 What will the queue store at initial level?
@saumya0908
saumya0908 / FAQ
Last active December 30, 2021 13:04
Vertical Order Sum Of A Binarytree
Q.1 What is the use of finding width of the binary tree?
ANS: The width of the binary tree will decide the total no. of vertical levels present and also the size of arraylist.
Q.2 Why we are creating arraylist?
ANS: To store the sum of all nodes present at each vertical level where the index of arraylist represent the vertical level indexing of binary tree.
Q.3 What we will store in queue?
@saumya0908
saumya0908 / FAQ
Last active December 30, 2021 12:13
Left View Of A Binarytree
Q.1 What methodology is implemented to print Left View Of A Binary Tree.
ANS: Level Order Traversal on the tree is implemented .
Q.2 Why are we using queue?
ANS: Queue is used over here to keep the track of point where we are changing the levels in the tree
Q.3 Discuss the Time Complexity to print Left View Of A Binary Tree.