UKG Coding Question – Solved

7 Live
There is an integer array arr[n] and an integer value d. The array is indexed from 1 to n. Count the number of distinct triplets (i, j, k) such that 0 < i < j < k ≀ n and the sum (a[i] + a[j] + a[k]) is divisible by d. Example: a = [3, 3, 4, 7, 8], d = 5. The following triplets are divisible by d = 5. These are the triplets whose sum is divisible by d (1-based indexing): Β· indices (1, 2, 3), sum = 3 + 3 + 4 = 10 Β· indices (1, 3, 5), sum = 3 + 4 + 8 = 15 Β· indices (2, 3, 4), sum = 3 + 4 + 8 = 15 Since there is no other triplet divisible by d = 5, return 3. Function Description: Complete the function getTripletCount in the editor below. getTripletCount has the following parameters: int a[n]: an array of integers int d: an integer Returns: int β€” the number of distinct triplets Constraints: Β· 1 ≀ a[i] ≀ 10^9 Β· 2 ≀ d ≀ 10^9 Input Format For Custom Testing: Sample Case 0 Sample Input For Custom Testing: STDIN 2 FUNCTION 4 a = [2, 3, 1, 6] 1 6 3 Sample Output: 3

Asked in: UKG

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |