Home > database >  What is wrong my implementing of binary search algorithm
What is wrong my implementing of binary search algorithm

Time:05-26

I am trying to fix the one task from Coursera regarding Binary Search Algorithm. When I am testing my solution it works well. But the Autograder of Coursera is not accepting my solution and throwing that . What am I missing ?

Failed case #17/36: Wrong answer

(Time used: 0.06/5.00, memory used: 46239744/536870912.)

The task Input Format -- The first line of the input contains an integer n and a sequence a0 < a1 < ... < an−1 of n pairwise distinct positive integers in increasing order. The next line contains an integer k and k positive integers b0,b1,...,bk−1.

Constraints -- 1 ≤ n,k ≤ 10^4; 1 ≤ a[i] ≤ 10^9 for all 0 ≤ i < n; 1 ≤ b[]j ≤ 10^9 for all 0 ≤ j < k;

Output Format -- For all i from 0 to k−1, output an index 0 ≤ j ≤ n−1 such that aj = bi or −1 if there is no such index.

Sample 1.

Input:

5

1 5 8 12 13

5

8 1 23 1 11

Output:

2 0 -1 0 -1

In this sample, we are given an increasing sequence

  • Related