Skip to content

Instantly share code, notes, and snippets.

@samarthsewlani
Created June 6, 2024 09:57
Show Gist options
  • Save samarthsewlani/51556d7f018c13fa84fcbeb9ed776d03 to your computer and use it in GitHub Desktop.
Save samarthsewlani/51556d7f018c13fa84fcbeb9ed776d03 to your computer and use it in GitHub Desktop.
Pairs of Songs With Total Durations Divisible by 60
//https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/
class Solution {
public int numPairsDivisibleBy60(int[] time) {
int n = time.length, count = 0;
for(int i=0;i<n;i++) time[i] %= 60;
Map<Integer, Integer> visited = new HashMap<>();
for(int i=0;i<n;i++){
int value = (60-time[i])%60;
if(visited.containsKey(value)){
count += visited.get(value);
}
visited.put(time[i], visited.getOrDefault(time[i], 0) + 1);
}
return count;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment