Max Distance between two occurrences of the same element

Given an array of integers where elements may be repeating in the array. Find the maximum distance between two occurrences of the same element in […]

Maximum consecutive integers present in an array

Given an array of integers. Find the maximum number of consecutive integers present in the array. For example, if the array is: int arr[] = […]

Recursive Bubble Sort

Give the recursive implementation of the Bubble Sort algorithm

Find two elements in an array whose sum is x

Given an array of integers and a number x. check if there exists two elements in the array whose sum = x.

Find numbers with more than k-bits in their binary representations

Given an array of unsigned integers, print all the numbers that have more than k bits set in their binary representation. For example, if k […]

Water overflowing from glass arranged in form of triangle

Glasses are arranged in the form of triangle (on top of each other) as shown below: 1 2 3 4 5 6 7 8 9 […]

Maximum (or minimum) sum of subarray of size k

Given an array of n integers, find the sub-array of length k with maximum sum. For example, Input Array: {6, 4, 3, 5, 1, 9, […]

Consecutive numbers with sum equal to n

Given a positive integer n, print the consecutive numbers whose sum is equal to n. For example, n = 20 Output: 2, 3, 4, 5, […]

Check duplicate parenthesis in an expression

A valid mathematical expression can also have duplicate parenthesis as shown below: ((a+b)) (((a+(b)))+(c+d)) Write code to find if an expression has duplicate parenthesis. You […]

Next greater element

Print Next Greater Element for every element in the array. The Next greater Element of element x is first greater element on its right side. […]