Skip to content

Instantly share code, notes, and snippets.

@fancellu
Last active November 10, 2015 16:42
Show Gist options
  • Save fancellu/e2219582421b484bfe40 to your computer and use it in GitHub Desktop.
Save fancellu/e2219582421b484bfe40 to your computer and use it in GitHub Desktop.
k-subSequence for HackerRank
def kSub(k:Int,nums:Array[Int]):Long={
val count=for {
i<-0 to nums.size
j<-i to nums.size
slice=nums.slice(i, j)
sum=slice.sum
} yield if (sum!=0 && (sum%k)==0) 1 else 0
count.sum
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment