IBM OA questions
Anonymous User
758

Platform: Hackerrank

Q1) Return the sum of an array.

Q2) Given 2 arrays arr1 and arr2, return an array such that for each element in arr1 find the smallest index in arr2 that contains a value greater than the element from arr1. If there is no such index return -1

Eg:

arr1 = [3,1,5,6]
arr2 = [4,1,5,6]

sol = [0, 0, 3, -1]

My approach: Create a max prefix array, for each index in arr1 if the element is smaller than the maximum element in arr2 apply binary search else return -1. Let me know if the approach is right and optimal. Could pass all test cases.

Comments (4)