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.
Perhaps this would be easy to understand for you. First of all we save the remainder and then we take its complement to make a pair. For example, in the sample test case, if the remainder is 1, then we will take its complement which is 2, and we will look for a number if divided, would give a remainder 2. Therefore, the sum of this pair will be divisible by 3 (which is k). Also, it gives O(n) solution.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Divisible Sum Pairs
You are viewing a single comment's thread. Return to all comments →
Perhaps this would be easy to understand for you. First of all we save the remainder and then we take its complement to make a pair. For example, in the sample test case, if the remainder is 1, then we will take its complement which is 2, and we will look for a number if divided, would give a remainder 2. Therefore, the sum of this pair will be divisible by 3 (which is k). Also, it gives O(n) solution.