FastPrepStock Prices
Problems/Stock Prices

Stock Prices

Rubrik logoRubrik● EasyINTERNOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

The cost of a stock on each day is given in an array, arr. An investor wants to buy the stocks in triplets such that the sum of the cost for three days is divisible by d. The goal is to find the number of distinct triplets (i, j, k) such that i < j < k and the sum (arr[i]+arr[j]+arr[k]) is divisible by d.

Function

getTripletCount(arr: int[], d: int) → int

Complete the function getTripletCount in the editor below. The function must return an integer denoting the total number of distinct triplets.

getTripletCount has the following parameters:

  1. int arr[n]: an array of integers
  2. int d: the divisor

Examples

Example 1

arr = [3, 3, 4, 7, 8]d = 5return = 3

The triplets whose sum is divisible by d are shown.

  • Triplet with indices - (0, 1, 2), sum = 3+3+4 = 10
  • Triplet with indices - (0, 2, 4), sum = 3+4+8 = 15
  • Triplet with indices - (1, 2, 4), sum = 3+4+8 = 15

Hence, the answer is 3.

Constraints

  • 3 ≤ n ≤ 10^3
  • 1 ≤ arr[i] ≤ 10^9
  • 2 ≤ d ≤ 10^6

More Rubrik interview questions

  • Delete and Freeze GameOA · Seen Nov 2026
  • Delete K Subsets for Maximum ScoreOA · Seen Nov 2026
  • Distribute Elements Into Two Arrays IIOA · Seen Nov 2026
  • Minimum Replacements to Sort the ArrayOA · Seen Nov 2026
  • All Balanced Strings from Minimum Parenthesis InsertionsONSITE INTERVIEW · Seen Nov 2026
  • Insert into a Left-Complete Binary TreeONSITE INTERVIEW · Seen Oct 2026
  • Thread-Safe Request Counts by AttributeONSITE INTERVIEW · Seen Oct 2026
  • Minimum Swaps To Binary PalindromeOA · Seen Apr 2026
  • Get Minimum OperationsOA · Seen Nov 2024
  • Horizontal Pod AutoscalerOA · Seen Nov 2024

Similar questions at other companies

  • Count Valid Square PairsAuxoAI · OA
  • Basic Item DiscountsPalantir · OAPalantir interview questions
  • Distinct Products After Removing One ElementHSBC · OAHSBC interview questions
  • Find Max Sum with Same First and Last DigitMicrosoft · OAMicrosoft interview questions
  • Get Max Discount PairsAmazon · OA
  • Find Number of Interesting PairsThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
  • Nums That Are Divisible by N 🍋Two Sigma · OATwo Sigma interview questions
  • Find Mean and ModeCisco · OACisco interview questions
  • Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
  • Get Triplet CountIBM · OAIBM interview questions
All Rubrik interview questionsSee Rubrik hiring insights
Saved
class Solution {
    public int getTripletCount(int[] arr, int d) {
      // write your code here
    }

}
Checking account…