This video is about Divisible Sum Pairs problem from HackerRank.
Problem Statement:
You are given an array of integers and a positive value k, Find and print the number of pairs where i is less than j and ar[i]+ar[j] is divisible by k .
#HackerRank #Algorithm #Interview
Problem:
[ Ссылка ]
Sample Code:
Solution 1:
def divisibleSumPairs(n, k, ar):
c=0
for i in range(n):
for j in range(n):
if i less than j and (ar[i]+ ar[j])%k==0: // use angle bracket sign
c+=1
return c
Solution 2:
def divisibleSumPairs(n, k, ar):
return sum(1 for i in range(n) for j in range(n) if i less than j and (ar[i]+ar[j])%k==0)
For 1 : 1 Tutoring
WhatsApp contact : 7278222619
mail: jaiswalsatya93@gmail.com
You can support via UPI : sattujaiswal@okhdfcbank
Follow me on:
whatsapp:
[ Ссылка ]
Facebook:
[ Ссылка ]
Linkedin:
[ Ссылка ]
Instagram:
[ Ссылка ]
Ещё видео!