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 Distance Between two Occurrences of Same Element in Array

Suppose you are given an array with some repeated numbers. We have to find the maximum distance between the two same occurrences of a number with different index, present in an array. Example Input: array = [1, 2, 3, 6, 2, 7] Output: 3 Explanation: Because elements at array [1] …

Read moreMaximum Distance Between two Occurrences of Same Element in Array

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

Minimum swaps required to bring all elements less than or equal to k together

The problem “Minimum swaps required to bring all elements less than or equal to k together” states that you have an integer array. The problem statement asks to find out the smallest count of swaps that will be required to get the elements together which are less than or equal …

Read moreMinimum swaps required to bring all elements less than or equal to k together

Sorting using trivial hash function

The problem “Sorting using trivial hash function” states that you are given an integer array. An array can be containing both negative and positive numbers. The problem statement asks to sort the array using Trivial Hash Function. Example arr[] = {5,2,1,3,6} {1, 2, 3, 5, 6} arr[] = {-3, -1, …

Read moreSorting using trivial hash function

Find duplicates in a given array when elements are not limited to a range

The problem “Find duplicates in a given array when elements are not limited to a range” states that you have an array consisting of n integers. The problem statement it to find out the duplicate elements if present in the array. If no such element exists return -1. Example [ …

Read moreFind duplicates in a given array when elements are not limited to a range