Google | Phone | Count of tuples formed within given distance

Anonymous User
790
Sep 13, 2022
Sep 13, 2022

Location: India
Date: September 2022

Question:

Input: Three sorted integer arrays: v1, v2, v3 with same length n, and a distance: t
Output: Number of tuples [x, y, z] satisfying:
x in v1, y in v2, z in v3, and |x - y| <= t, |y - z| <= t, |x - z| <= t

Example:
v1 = [1, 5, 10]
v2 = [2, 4, 8] 
v3 = [3, 5, 12]
t = 3
Output = 7 
Comments (5)