Pairs of Songs With Total Durations Divisible by 120
Updated
Problem statement
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[]) → intExamples
Example 1
time = [40,80,200,160,60,180]return = 5Five 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 = 2The 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 = 3Every pair works: 60 + 300 = 360, 60 + 180 = 240 and 300 + 180 = 480.
Constraints
1 <= time.length <= 6 * 10^41 <= time[i] <= 500
More Cashfree Payments interview questions
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