Rearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i

Suppose you have an integer array. The problem statement asks to rearrange the array in such a way that the elements at even position in an array should be greater than all elements before it and the elements at odd positions should be less than the elements before it. Example …

Read moreRearrange Array such that arr[i] >= arr[j] if i is even and arr[i] <= arr[j] if i is odd and j < i

Maximum difference between frequency of two elements such that element having greater frequency is also greater

Suppose, you have an integer array. The problem statement asks to find out the maximum difference between the frequency of any two distinct elements of a given array, but the element with the greater frequency should also be greater in value than the other integer. Example Input: arr[] = {2,4,4,4,3,2} …

Read moreMaximum difference between frequency of two elements such that element having greater frequency is also greater

Longest Subarray Having Count of 1s One More than Count of 0s

We have given an array of integers. An array contains 1’s and 0’s only. The problem statement asks to find out the length of the longest Sub-Array which having the quantity of 1’s digit is just one more than the count of 0’s in a sub-array. Example Input: arr[] = …

Read moreLongest Subarray Having Count of 1s One More than Count of 0s

Maximum Array from Two given Arrays Keeping Order Same

Suppose we have two integers array of same size n. Both of the arrays can contain common numbers as well. The problem statement asks to form the resultant array that contains the ‘n’ maximum values from both of the arrays. The first array should be prioritized (elements of the first …

Read moreMaximum Array from Two given Arrays Keeping Order Same

Maximum Number of Chocolates to be Distributed Equally Among k Students

“The maximum number of chocolates to be distributed equally among k students” states that you are given n boxes that have some chocolates in it. Suppose there are k students. The task is to distribute the maximum number of chocolates among k students equally, by selecting consecutive boxes. We can …

Read moreMaximum Number of Chocolates to be Distributed Equally Among k Students

Maximum subsequence sum such that no three are consecutive

The problem “Maximum subsequence sum such that no three are consecutive ” states that you are given an array of integers. Now you need to find a subsequence that has the maximum sum given that you cannot consider three consecutive elements. To recall, a subsequence is nothing but an array …

Read moreMaximum subsequence sum such that no three are consecutive

Check if Array Contains Contiguous Integers With Duplicates Allowed

You are given an array of integers which can contain duplicate elements as well. The problem statement asks to find out if it is a set of contiguous integers, print “Yes” if it is, print “No” if it is not. Example Sample Input: [2, 3, 4, 1, 7, 9] Sample …

Read moreCheck if Array Contains Contiguous Integers With Duplicates Allowed

Sequences of given length where every element is more than or equal to twice of previous

The problem “Sequences of given length where every element is more than or equal to twice of previous” provides us with two integers m and n. Here m is the largest number that can exist in the sequence and n is the number of elements that must be present in the …

Read moreSequences of given length where every element is more than or equal to twice of previous