Category Archives: Algorithms

Minimum Substring of S Containing Elements in T

Given a random string S and another string T with unique elements, find the minimum consecutive sub-string of S such that it contains all the elements in T. For example: S=adobecodebanc T=abc answer=’banc’ The problem is similar to find all anagram of a string as substring of another given string. Please read my previous article here to […]

Max sum subsequence with non-consecutive elements – Kadane’s Algorithm (DP)

Given an array of integer. Find the maximum sum subsequence such that elements are not consecutive. For example, A = [−2, 1, −3, 4, −1, 2, 1, −5, 4] then max sum=11 with the subarray [1, 4, 2, 4]. First of all, lets solve the problem with less constraint. Suppose we need to find out […]

Maximum number of overlapping intervals – Merge Overlapping Intervals – Max Task Load

Given a set of intervals, how do we find the maximum number of intervals overlapping at any point of time. For example – { (0,2), (3, 7), (4,6), (7,8), (1,5) }. The maximum number of intervals overlapped is 3 during (4,5). A very simple solution would be check the ranges pairwise. This is certainly very […]

Maximum area rectangle of histogram

Given n non-negative integers representing the height of bars of width one of a histogram, find the maximum area rectangle of histogram i.e. the maximum area rectangle contained in the histogram. For example, H = [4, 2, 1, 8, 6, 8, 5, 2] then the histogram has a rectangle of area of 20 showed in […]