pranjay-poddar / Data-Structures-And-Algorithms

Important data structure and algorithms codes and concept's open-source repository.
https://bit.ly/30DLzuJ
MIT License
48 stars 109 forks source link

Create 5)Smallest subarray with all occurrences of a most frequent el… #205

Closed AyushMittal10 closed 2 years ago

AyushMittal10 commented 2 years ago

Q)

Given an array, A. Let x be an element in the array.
x has the maximum frequency in the array. Find the smallest subsegment
of the array which also has x as the maximum frequency element.

Input Format An integer n representing size of array n elements of array

Constraints 1 ≤ N ≤ 10^5 1 ≤ A[i] ≤ 10^5

Output Format The smallest subsegment of the array

Sample Input 8 4 1 1 2 2 1 3 3

Sample Output 1 1 2 2 1

Explanation The most frequent element is 1. The smallest subarray that has all occurrences of it is 1 1 2 2 1