FastPrepPairs of Songs With Total Durations Divisible by 120
Problems/Pairs of Songs With Total Durations Divisible by 120

Pairs of Songs With Total Durations Divisible by 120

Cashfree Payments logoCashfree Payments● MediumFULLTIMEPHONE SCREEN

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported from a Cashfree Payments SDE-2 interview for a backend role, by a candidate with about 3.5 years of experience. The first of three technical rounds was a coding round with two problems, and this was the second one. Cost in time and memory came up in that round too, along with a request for a better approach.

The report gives only the problem name, which says the total length of a pair of songs must be divisible by 120. It has no statement, examples or limits. We use the usual meaning of this named problem with 120 kept, and the usual limits for it, and all examples and tests are ours. The editorial goes from checking every pair to counting songs by their remainder.

Our version is about 90% the same as the reported question.

You are given a list of songs, where time[i] is the length of the i-th song in seconds.

Return the number of pairs of songs whose total length in seconds is divisible by 120. Formally, count the pairs of indices i and j with i < j and (time[i] + time[j]) % 120 == 0.

Each pair is counted once, and a song is never paired with itself. Two different songs with the same length are different songs.

Function

numPairsDivisibleBy120(time: int[]) → int

Examples

Example 1

time = [40,80,200,160,60,180]return = 5

Five pairs have a total that is a multiple of 120: 40 + 80 = 120, 40 + 200 = 240, 80 + 160 = 240, 200 + 160 = 360 and 60 + 180 = 240. No other pair works, for example 40 + 160 = 200.

Example 2

time = [100,240,140,360]return = 2

The total only has to be a multiple of 120, not exactly 120: 100 + 140 = 240 and 240 + 360 = 600 both count. The other four pairs give 340, 460, 380 and 500.

Example 3

time = [60,300,180]return = 3

Every pair works: 60 + 300 = 360, 60 + 180 = 240 and 300 + 180 = 480.

Constraints

  • 1 <= time.length <= 6 * 10^4
  • 1 <= time[i] <= 500

More Cashfree Payments interview questions

  • Largest SubsequencesOA · Seen Aug 2022
  • Minimum Server VulnerabilityOA · Seen Aug 2022

Similar questions at other companies

  • Logger Rate Limiter with Every-Arrival HistoryGoogle · PHONE SCREENGoogle interview questions
  • Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Filter, Sort, and Deduplicate Scheduled TasksRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
  • Insert Delete GetRandom O(1)Charta Health · PHONE SCREENCharta Health interview questions
  • Longest Consecutive SequenceKotak Mahindra Bank · PHONE SCREENKotak Mahindra Bank interview questions
  • Longest Consecutive SequenceJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
  • Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
See Cashfree Payments hiring insights
Saved
class Solution {
    public int numPairsDivisibleBy120(int[] time) {
      // Write your code here.
    }

}
Checking account…