Paypal | MTS | April 2021

Paypal reached out to me in March 2021. Below is first round of interview.

Given input array.
Arr = [4, 8, 5,3,1]

Output all pair of elements satisfying below condition.
(4,1) (8,2) (8,3) (8,1) (5,1) (3,1)

Condition:
(i,j) -> i and j are array indexes, i < j
Arr[i] > 2*Arr[j]

I have her solution using O(n2), she asked for better solution. We later reached to merge sort based solution. It can solved in similar way. In merge sort, the place where we compare if element is greater or lesser, replace that statement with arr[i] > 2*arr[j]. This lead to soltuion in O(n log n). I explained her full solution and entire interview hour went in solution finalization.

Similar to : https://leetcode.com/problems/reverse-pairs/

Rejected :(

Comments (5)