Uber OA | 2021

Online Assesment questions
2 coding questions of medium-hard difficulty levels

  1. Given 2 arrays a and b containing integer elements, and an element d. You need to find the number of elements in a that satisfy the given condition for all the elements of b. |x - y| > d where x belongs to a and y belongs to b . For e.g a = [3, 5, 9] and b = [2, 4, 13] and d = 3.
    all the abs diff of a[0] are [1,1,10] since 1 is <=3, a[0] is not acceptable.
    all the abs diff of a[1] are [3,1,8] since 1 or 3 is <=3, a[1] is also not acceptable.
    all the abs diff of a[2] are [7,5,4] since 7 or 5 or 4 are > 3 , so a[2] is acceptable. Hence the answer 1.

  2. Given an array arr of size n and element m. Find the maximum of minimums of all the subarrays of arr
    of size m.

I solved the 1st question using set and lower_bound. and I solved the 2nd question using deque by maintaing minimum at the front of the deque.

NOTE: variants of these 2 questions are present on leetcode.

EDIT:
Question 2: https://leetcode.com/problems/sliding-window-maximum/

Comments (10)