K Empty Slots

Given N flowers. One flower blooms per day. Array flowers[i] gives the flower position (1-based) blooms at i + 1th day. Find the first day where there are k not bloomed flowers between two flowers already bloomed. [Optimal]Two Pointers/Sliding Window Solution Put in another word, we need to find two flowers such that all the […]

Degree of an Array

Degree of an Array The degree of an array is defined as the number of occurrence of the most elements in an array. The problem is related to find the shortest subarray that contains elements with that degree. This solution builds a map from elements to their count, meanwhile find all the elements with the […]

Two Three Four Sum

MUST KNOWN Two Sum Determine if two numbers from the given array sum up to the target. The idea is to maintain a map from number to its index. Build the map while traversing the list. Because cannot have duplicate solutions, it implies that there is no duplicates in the list. Each iteration, check if […]