- a single duplicate number exists
- multiple duplicate numbers exist
Showing posts with label cormen. Show all posts
Showing posts with label cormen. Show all posts
Find duplicates in an array
Labels: array, CLRS, cormen, duplicate, interview question
Given an array of size 'n', containing elements from 1 to 'n', find out if there are any duplicates in the array. Solve this, if
Find subarray with maximum sum
Labels: array, CLRS, cormen, interview question
Given an array of size n, containing positive and negative integers, find the longest sub-array such that the sum of the elements in the sub-array is the maximum.
For example,
Given array :
10, 8, -5, 1, -27, 5, 7, -5, 11
the sub array should be : 10, 8
Source : CLRS & this sample interview question
For example,
Given array :
10, 8, -5, 1, -27, 5, 7, -5, 11
the sub array should be : 10, 8
Source : CLRS & this sample interview question
[ALGO] Water jugs problem
Labels: algorithms, cormen, sort, water jugs
Suppose that you are given 'n' red and 'n' blue water jugs, all of different shapes and sizes. All red jugs hold different amounts of water, as do the blue ones. For every red jug, there is a blue jug that holds the same amount of water & vice versa.
How can you find the grouping of the jugs into pairs of red & blue jugs that hold the same amount of water, in the minimum number of comparisons.
Operations allowed
How can you find the grouping of the jugs into pairs of red & blue jugs that hold the same amount of water, in the minimum number of comparisons.
Operations allowed
- always compare between a red and a blue jar (no two reds, no two blues)
- fill water in red / blue jug
- pour from red jug to blue (& vice versa). This will help compare the capacity of the jugs.
Subscribe to:
Posts (Atom)



