Finding Numbers

Interview

Time limit1sMemory limit128 MB

Summary
Given N integers and M queries, output for each query whether it exists in the array, requiring an efficient lookup method.
Level

Easy3 of 10

Topics
Binary search, Sorting, Hash map
Solved
No attempts yet

Problem

You are given an array of N integers A[1], A[2], ..., A[N]. Write a program that determines whether each query integer X is contained in the array.

Input

The first line contains a natural number N (1 <= N <= 100,000).

The second line contains N integers A[1], A[2], ..., A[N].

The third line contains a natural number M (1 <= M <= 100,000).

The fourth line contains M integers to check. Every integer is at least -2^31 and less than 2^31.

Output

For each of the M query integers, print 1 if it exists in array A and 0 otherwise, one answer per line.

Examples1

  1. Example 1

    Input
    5
    4 1 5 2 3
    5
    1 3 7 9 5
    
    Expected output
    1
    1
    0
    0
    1