Find the Next!
Tag(s):

## Algorithms, Arrays, Binary tree, Easy, Hash Maps, Implementation, One-dimensional, Quick Sort, Quicksort, Sorting

Problem
Editorial
Analytics

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}$
SAMPLE INPUT
5 2
2 7 5 9 15
3
9
SAMPLE OUTPUT
4
10
Explanation

For the first query, the minimum element greater than 3 and not present in the given array is 4. Similarly, for the second query, the answer is 10.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

## CODE EDITOR

Initializing Code Editor...

## This Problem was Asked in Challenge Name

ThoughtWorks Coding Challenge for Women

OTHER PROBLEMS OF THIS CHALLENGE
• Algorithms > String Algorithms