package leetcode;

/**
 * https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/
 */
public class Problem1013 {
    public int numPairsDivisibleBy60(int[] time) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1013 prob = new Problem1013();
        System.out.println(prob.numPairsDivisibleBy60(new int[]{30, 20, 150, 100, 40})); // 3
        System.out.println(prob.numPairsDivisibleBy60(new int[]{60, 60, 60})); // 3
    }
}

package leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * https://leetcode.com/problems/pairs-of-songs-with-total-durations-divisible-by-60/
 */
public class Problem1013 {
    public int numPairsDivisibleBy60(int[] time) {
        int answer = 0;
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < time.length; i++) {
            int a = time[i] % 60;
            int b = (60 - a) % 60;
            if (map.containsKey(b)) {
                answer += map.get(b);
            }
            if (!map.containsKey(a)) {
                map.put(a, 1);
            } else {
                map.put(a, map.get(a) + 1);
            }
        }
        return answer;
    }
}

Solve problem 1013