Min Common Integer

Image placeholder 9899

(This question has been seen in the interviews of the following companies: Tiktok)
Tiktok Online Assessment Questions 2023

ByteDance is developing a new algorithm to implement in an upcoming software. The algorithm runs on a sequence of integers. Given an array data of size n, where the value of the ith integer is represented by the array data[i], the algorithm will run on data as:

- For every integer k, where 1 <= k < n. The algorithm will return the minimum common integer that occurs in all of the subarrays of the array data having length k.
- If there is no common integer occurring in any subarray of length k, then the algorithm will return -1. 

Given an integer n, and an array data, find the array that the algorithm will return after running on data.

Example
Given, n = 5, data = [4, 3, 3, 4, 2]

subarrays | minimun comon integer
[4][3][3][4][2] | -1
[4,3][3,3][3,4][4,2] | -1
[4,3,3],[3,3,4],[3,4,2] | 3
[4,3,3,4][3,3,4,2] | 3
[4,3,3,4,2] | 2 

Hence, the algorithm will return the array [-1, -1, 3, 3, 2] after running on data

Function Description
Complete the function minimumCommoninteger in the editor below

minimumCommoninteger has the following parameter: 
int data[n]: an array of integers.

Constraints
2 <= n <= 2 * 10^5
1 <= data[i] <= n

More examples
Example2
n = 3
data = [3,2,3,1]
Sample output:
-1,3,2,1

Exmaple3
n = 5
data = [2,4,2,3,5]
Sample output:
-1,-1,2,2,2




Get one-to-one training from Google Facebook engineers

Top-notch Professionals

Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.

Customized Private Class

Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.