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 […]

Count of Smaller Numbers after Self

Given an array, for each number in the array count the number of elements to its right are smaller than it. BST Solution This is the BST solution. We walk through the array from right to left and insert each node into the BST (nodes are inserted as leafs). Note that we are walking from […]