Codenation Interview Experiance | DS-Algo Round

Q1:  How many sets are possible from an array of size n, such that each number in the set divides the consecutive number in the set. You can use one value only once in a particular set.

Approach: Sort the input array, Iterate in the input array and iterate through the divisors of A[i] and add the dp[divsors] to dp[A[i]]

Edge Case: When the array contains zero, do not iterate through zeros and answer will be 2*ans+1

Q2: Given a tree. A signal starts at the root at time t=0, at every second each node which has the signal can pass it to one of its children and the signal persists, calculate the minimum time such that all nodes in the tree will have the signal.
 

Approach:  Can be solved with dfs+dp, if the answers to all the children of a node are sorted in descending order, the answer to the node will be maximum of (ans[child]+i+1, ans[node]), where i is the index of the child, and the answer for the leaf node will be 1 as a base case.




Write your Interview Experience or mail it to contribute@geeksforgeeks.org

My Personal Notes arrow_drop_up

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.