Approach #1: Insert Into Sorted Structure [Accepted] Intuition Let's add flowers in the order they bloom. When each flower blooms, we check it's neighbors to see if they can satisfy the condition with the current flower. Algorithm We'll maintain active , a sorted data structure containing every flower that has currently bloomed. When we add a flower to active , we should check it's lower and higher neighbors. If some neighbor satisfies the condition, we know the condition occurred first on this day. Complexity Analysis Time Complexity (Java): O(N \log N) O ( N lo g N ) , where N N is the length of flowers . Every insertion and search is O(\log N) O ( lo g N ) . Time Complexity (Python): O(N^2) O ( N 2 ) . As above, except list.insert is O(N) O ( N ) . Space Complexity: O(N) O ( N ) , the size of active . Approach #2: Min Queue [Accepted] Intuition For each contiguous block ("window") of k po...
Project Weekay | Resume | LinkedIn Profile
NodeJS, AWS, MongoDB, ReactJS, Django, Python, ML with Scikit Learn, Matplotlib, Seaborn
Engineering, UX, Marketing, Product Designing, Business
sayhellotovinit@gmail.com | +91 99239 08880 | Pune, India