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
- Discussions
Divisible Sum Pairs
Divisible Sum Pairs
Sort by
recency
|
192 Discussions
|
Please Login in order to post a comment
Hi Folks, I refered this video -> https://youtu.be/9qPtxAY9bKA?si=GxoR7wwEyyVYO3vV
In this video, the author teaches me how to optimize the code, because normally in the bruteforce approach we will use two nested for-loop to achieve the solution. If we use two nested for-loop it will be O(n^2) complexity. The author teaches in java in the video, my solutions in javascript is below and it will gives you Big O of n complexity.
def divisibleSumPairs(n, k, ar): combinations = 0 for i in range(n): for j in range(i + 1, n): if (ar[i] + ar[j]) % k == 0: combinations += 1 return combinations
pythob
Python:
c