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.
Divisible Sum Pairs
Divisible Sum Pairs
Sort by
recency
|
2467 Discussions
|
Please Login in order to post a comment
This approach greatly improves performance while keeping the logic simple and clear. It’s a great exercise to learn about optimizing loops and using modular properties in programming challenges. If you want to explore or attempt this problem yourself, click here to open it on HackerRank.
def divisibleSumPairs(n, k, ar): count=0 for i in range(len(ar)-1): first=ar[i] for j in range(i+1,len(ar)): second=ar[j] if (first+second)%k==0: count +=1 return count
condition should be i <= j not i < j inshallah, correct ?
O(n) solution in JavaScript
Is there any solution but O(n^2) ?