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.
Hey geek! It’s time to become a success story instead of reading them. Check out our most renowned DSA Self Paced Course, now at a student-friendly price and become industry ready. And if you are looking for a more complete interview preparation resource, check out Complete Interview Preparation Course that will prepare you for the SDE role of your dreams!
Feeling prepared enough for your interview? Test your skills with our Test Series that will help you prepare for top companies like Amazon, Microsoft, TCS, Wipro, Google and many more!