Pinterest • The world’s catalogue of ideas

Given an array of n elements which contains integers from 0 to n-1 only. The numbers can appear any number of times. Find the repeating numbers. Check out the solution in O(n) time and in O(1) extra space. Java visualization is provided in algorithm visualization section. Java code is given in the code snippet section.

Number of clusters of 1s OR Number of Islands - IDeserve

Find maximum element from each sub-array of size 'k'| Set 1

Find maximum element from each sub-array of size 'k'| Set 2 - IDeserve

The basic idea to solve this problem is to find out number of 1's on the both side of each 0. In this intuitive algorithm, what we do is that we build a count array which would keep track of number of 1's on both side of each 0.

Find index of 0 to replace to get longest continuous sequence of 1s - IDeserve

Positive elements should be placed at even indices and negative elements should be placed at odd indices. The order of same signed elements should remain same. It is not guaranteed that positive and negative elements are equal in number.

For every element a[i] in array 'a', we need to find the largest element less than a[i](say leftLargest[i]) in left sub-array a[0 .. i-1]and largest element greater than a[i](say rightLargest[i]) in right sub-array a[i+1 .. lengthOfArray-1].

Given an array of positive numbers, find sub-sequence of length three having maximum product. The elements of sub-sequence should be in increasing order. For example, for the input array {6, 7, 8, 1, 2, 3, 9, 10} output should be sub-sequence 8,9,10.