Google Onsite round question for L3 role

Anonymous User
1199
Dec 01, 2024
Dec 01, 2024

In the 3rd google onsite round, I was asked the question similar to below one related to arrays:

Given are Three Arrays : A, B, C

  • Non-negative integers
  • SORTED ARRAYS
  • have the same length N

A non-negative integer D.

Find the number of triplets (i, j, k) such that, they follow these constraints:
|A[i] - B[j]| <= D
|A[i] - C[k]| <= D
|B[j] - C[k]| <= D

|max() - min()| <= D

Example :
Input: A = [1, 5, 5], B = [3, 4, 5], C = [6, 6, 8], D = 1
output: 2
Expalnation: 5,5,6 triplet from indices (2,2,0), (2,2,1), gives 2 triplets

Solve the question in O(nlogn) time complexity and O(1) space complexity.

Comments (8)