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.
Submissions
Please login to view your submissions
Similar Problems
Points:20
322 votes
Tags:
Ad-HocEasyGreedy Algorithms
Points:20
348 votes
Tags:
EasyGreedy AlgorithmsOpenString Manipulation
Points:20
8 votes
Tags:
Greedy AlgorithmsBasics of Greedy AlgorithmsAlgorithms
Editorial