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.
funcdivisibleSumPairs(_int32,kint32,ar[]int32)int32{// Write your code here// A map that stores the remainder of each valueremainderMap:=make(map[int32]int32)// The number of found solutioncount:=int32(0)for_,value:=rangear{remainder:=value%k/* A complement remainder is a number whose initial number y when added to a value x returns a multiple of k */complementRemainder:=(k-remainder)%k// A value whose remainder is the complement remainderremValue,exists:=remainderMap[complementRemainder]//We add the number of values that align to the conditionifexists{count+=remValue}//Check if there's duplicate remainder//If A dup exists we add the number of duplicates availabletheDup,existsADuplicate:=remainderMap[remainder]ifexistsADuplicate{remainderMap[remainder]=theDup+1}else{remainderMap[remainder]=1}}returnint32(count)}
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 →
O(n) in Golang