We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The question asks to print pairs, for every i < j, where a_i + a_k is divisible by k. This constraint was placed in the problem so that we count pairs just once. For example, we want to count (a_i, a_j), but not also (a_j, a_i).
My solution counts each pair once. This is achieved by looping linearly through the input, and comparing each number to previous numbers only.
Divisible Sum Pairs
You are viewing a single comment's thread. Return to all comments →
The question asks to print pairs, for every i < j, where a_i + a_k is divisible by k. This constraint was placed in the problem so that we count pairs just once. For example, we want to count (a_i, a_j), but not also (a_j, a_i).
My solution counts each pair once. This is achieved by looping linearly through the input, and comparing each number to previous numbers only.
HackerRank solutions.