Ninja technique🥷 to ACE DSA Interviews.
60t % 60 gets the remainder from 0 to 59.mp.t in time, how many x satisfy (t + x) % 60 = 0.x % 60 = 60 - (t % 60), which is valid for the most cases.t % 60 = 0 then x % 60 should be 0 instead of 60.x % 60 = (60 - t % 60) % 60,x % 60 = (600 - t) % 60.class Solution {
public:
int numPairsDivisibleBy60(vector<int>& time)
{
vector<int> mp(60);
int n = time.size(), ans = 0;
for (int i = 0; i < n; i++) {
int rem = time[i] % 60;
ans += mp[(60 - rem) % 60];
mp[rem]++;
}
return ans;
}
};