Letter Combinations of a Phone Number

In letter combinations of a phone number problem, we have given a string containing numbers from 2 to 9. The problem is to find all the possible combinations that could be represented by that number if every number has some letters assigned to it. The assignment of the number is …

Read moreLetter Combinations of a Phone Number

Count Substrings with equal number of 0s, 1s and 2s

The problem “Count Substrings with equal number of 0s, 1s and 2s” states that you are given a string that has 0, 1, and 2 only. The problem statement asks to find out the number of substrings that contain equal no of 0, 1, and 2 only. Example str= “01200” …

Read moreCount Substrings with equal number of 0s, 1s and 2s

Generate all possible sorted arrays from alternate elements of two given sorted arrays

The problem “Generate all possible sorted arrays from alternate elements of two given sorted arrays” states that suppose you have two sorted arrays. The problem statement asks to find out all the possible sorted arrays, such that number should be arranged alternatively from the two given different arrays. Example ArrA[] …

Read moreGenerate all possible sorted arrays from alternate elements of two given sorted arrays

Range sum queries without updates

Problem Statement The problem “Range sum queries without updates” states that you have an array of integers and a range. The problem statement asks to find out the sum of all the elements within the given range. Example arr[]={10, 9, 8, 7, 6} Query: {(0, 4), (1, 3)} 40 24 …

Read moreRange sum queries without updates

Three way partitioning of an array around a given range

Problem Statement You are given an array of integers and a range of lowValue and highValue. The problem “Three way partitioning of an array around a given range” asks to partition the array such that array will be divided into three parts. The partitions of the arrays will be: Elements …

Read moreThree way partitioning of an array around a given range

Sum of minimum and maximum elements of all subarrays of size k

Problem Statement The problem “Sum of minimum and maximum elements of all subarrays of size k” states that you are given an array containing positive and negative integers, find the sum of minimum and maximum elements of all the sub-arrays of size k. Examples arr[] = {5, 9, 8, 3, …

Read moreSum of minimum and maximum elements of all subarrays of size k

Move all negative elements to end in order with extra space allowed

Problem Statement “Move all negative elements to end in order with extra space allowed” states that you are given an array containing positive and negative numbers both. The problem statement asks to move all the negative elements in the last of the array. Example arr[] = { 1,2,-3,-5,2,7,-9,-11 } 1, …

Read moreMove all negative elements to end in order with extra space allowed

Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest

Problem Statement Suppose you have an integer array. The problem “Rearrange an array in order – smallest, largest, 2nd smallest, 2nd largest, ..” asks to rearrange the array in such a way that the smallest number comes first and then the largest number, then second smallest and then the second …

Read moreRearrange an array in order – smallest, largest, 2nd smallest, 2nd largest