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] …

Group Multiple Occurrence of Array Elements Ordered by first Occurrence

You are given a question in which you have given an unsorted array with multiple occurrences of numbers. The task is to group all the multiple occurrences of array elements ordered by first occurrence. Meanwhile, the order should be the same as the number comes. Example   Input: [ 2, 3,4,3,1,3,2,4] …

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 …

Find Largest d in Array such that a + b + c = d

Problem Statement   Suppose you have an array of integers. Input values are all distinct elements. The problem “Find largest d in array such that a + b + c = d” asks to find out the largest element ‘d’ in the set such that a + b + c = …

Maximum sum of pairs with specific difference

The problem “Maximum sum of pairs with specific difference” states that you are given an array of integers and an integer K. Then we are asked to find out the maximum sum of independent pairs. We can pair two integers if they have an absolute difference of less than K. …

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 …

Longest subarray not having more than K distinct elements

The problem “Longest subarray not having more than K distinct elements” states that suppose you have an array of integers, the problem statement asks to find out the longest sub-array that having not greater than k different elements. Example   arr[] = {4, 3, 5, 2, 1, 2, 0, 4, 5} …

Find subarray with given sum (Handles Negative Numbers)

The problem “Find subarray with given sum (Handles Negative Numbers)” states that you are given an integer array, containing negative integers as well and a number called “sum”. The problem statement asks to print the sub-array, which sums up to a given number called “sum”.  If more than one sub-array …

Find elements which are present in first array and not in second

The problem “Find elements which are present in first array and not in second” states that you are given two arrays. Arrays consist of all the integers. You have to find out the numbers which will not be present in the second array but present in the first array. Example   …

Find missing elements of a range

The problem Find missing elements of a range” states that you are given an array of distinct elements within a particular range and a range given as low and high. Find all the missing elements within a range which is not present in an array. The output should be in …