Divide arrays
Practice
2.5 (63 votes)
Algorithms
Basics of greedy algorithms
C++
Greedy algorithms
Problem
87% Success 11264 Attempts 20 Points 3s Time Limit 256MB Memory 1024 KB Max Code
You are given an array \(A\) of \(N\) integers. Find the smallest index \(i\) \((1 \le i \le N - 1)\) such that:
- \(mex(A[1], A[2], .. , A[i]) = mex(A[i+1], A[i+2],... , A[N])\)
If no such index exists, print \(-1\).
Input format
- The first line contains an integer \(T\) denoting the number of test cases.
- For each test case:-
- The first line of each test case contains an integer \(N\) denoting the number of elements in array \(A\).
- The second line contains \(N\) space-separated integers denoting the elements of the array.
Output format
For each test case in a new line, print the smallest index satisfying the condition.
Constraints
\(1 \le T \le 10 \\ 1 \le N \le 10^5 \\ 0 \le A[i] \le 10^5 \\ \)
Note
- 1-based Indexing is followed.
- \(mex\) of an array of elements is defined as the minimum non-negative number missing from the array.
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
9 votes
Tags:
Greedy AlgorithmsAlgorithmsBasics of Greedy AlgorithmsGreedy algorithm
Points:20
12 votes
Tags:
AlgorithmsEasyGreedy AlgorithmsString Manipulationsorting
Points:20
7 votes
Tags:
AlgorithmsEasyGreedy AlgorithmsRecruit
Editorial
Login to unlock the editorial