Given an array of strings with commit ids, and a predicate isBuggy that returns if a single commit is buggy, write a program that finds the first buggy commit. - When a commit is buggy, we assume that all its children are buggy. - When a commit is not buggy, we assume that all its ancestors are not buggy. After solving it, I had to describe its time complexity and spatial complexity and how would I choose the test cases.
Sigiloso
This is really easy. Lets say that you have n-commits. Test for the 1st one. If it is buggy, tis is the beginning one, else try for nth commit. If this is buggy, try for (n/2)th one to test if it is buggy. If it is buggy, try for (n/4)th one or else try for (3n/4)th one. Thus, it is a recursive binary search until you find the first non-buggy one away from the buggy-one. Thus it is an O(lg(n)) solution.