Visa | Off-Campus | March 2026 | Divisible Triplets
VISA · Question · Posted Apr 2026
Problem Statement: Divisible Triplets The Objective: Given an array arr of length n and an integer d, count the number of unique triplets (i,j,k) such that 0≤i<j<k<n and the sum (arr[i]+arr[j]+arr[k]) is divisible by d. Example: arr = [3, 3, 4, 7, 8], d = 5 Output: 3 Triplets: Indices (0, 1, 2): 3+3+4=10 (Divisible by 5) Indices (0, 2, 4): 3+4+8=15 (Divisible by 5) Indices (1, 2, 4): 3+4+8=15 (Divisible by 5)
The full answer & interview discussion are available to premium members.
Log in Create a free account