90 minutes, two questions.
Question 1: Balanced Numbers
You're given a permutation array of 1 to N. For each length k from 1 to N, determine whether the k elements in the permutation whose values fall in the range 1 to k are exactly contiguous in the original array. Return a string of '1' and '0' indicating whether each k satisfies the condition.
Question 2: Minimum Reversal
You're given a directed graph with N nodes and N-1 edges — basically a directed tree. Pick any node as the "root", and every edge is required to point away from the root (diverging outward from it). If an edge's original direction doesn't satisfy that, it needs to be reversed. Which node should you pick as the root so that the number of edges you need to reverse is minimized? Find that minimum reversal count.
Discussion
Loading comments…