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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course. In case you are prepared, test your skills using TCS, Wipro, Amazon and Microsoft Test Serieses.