Searching Theory

Problems

Array search Searching an element in a sorted array Count 1's in binary array Square Root Majority Element Left Index Peak element Floor in a sorted array Minimum Number in a sorted rotated array Two repeated elements roof-top

Maximum water that can be stored between two buildings
Given an integer array that represents the heights of N buildings. The task is to delete N – 2 buildings such that the water that can be trapped between the remaining two buildings is maximum. The total water trapped between two buildings is a gap between them (the number of buildings removed) multiplied by the height of the smaller building. Examples:
Input: arr[] = {1, 3, 4}
Output: 1
Explanation: We have to calculate the maximum water that can be stored between any 2 buildings.
Water between the buildings of height 1 and height 3 = 0.
Water between the buildings of height 1 and height 4 = 1.
Water between the buildings of height 3 and height 4 = 0.
Hence maximum of all the cases is 1.
Input: arr[] = {2, 1, 3, 4, 6, 5}
Output: 8
We remove the middle 4 buildings and get the total water stored as 2 * 4 = 8


smallest-positive-missing-number number-of-occurrence More than n/k Occurrences allocate-minimum-number-of-pages subarray-range-with-given Median of 2 Sorted Arrays of Same Size