Find the Next!
Practice
3.7 (11 votes)
Algorithms
Arrays
Binary tree
Easy
Hash maps
Implementation
One Dimensional
Quick sort
Sorting
Problem
59% Success 12212 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given an array A of length N. For any given integer X, you need to find an integer Z strictly greater than X such that Z is not present in the array A. You need to minimise the value of Z.
Input format :
- First line : Two space seperated integers N and Q denoting the number of elements in array A and the number of queries respectively
- Second line : N space seperated integers denoting the array elements
- Next Q lines : Each line consists of an integer X
Output fomat :
- Print Q lines, each line denoting the answer to the corresponding query.
Constraints :
- \(1 \le N,Q \le 10^{5}\)
- \(1 \le A_{i},X \le 10^{9}\)
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
10 votes
Tags:
AlgorithmsEasyQuick SortSorting
Points:20
65 votes
Tags:
ApprovedEasySorting
Points:20
22 votes
Tags:
ApprovedData StructuresEasyOpenSorting
Editorial
Login to unlock the editorial