Skip to content

Instantly share code, notes, and snippets.

@alexnikol

alexnikol/.swift

Created Jun 30, 2020
Embed
What would you like to do?
PickingNumbers HackerRank - Solving
func pickingNumbers(a: [Int]) -> Int {
var repeatList = Array(repeating: 0, count: 100) //Generated list with 100 zeros
for i in 0..<a.count { //Count repeating of each item in input array
repeatList[a[i] - 1] += 1
}
var result = 0
for i in 0..<(repeatList.count - 1) {
let stepSum = repeatList[i] + repeatList[i + 1] //Sum of each item and next item
if stepSum > result { //The biggest met sum is our answer
result = stepSum
}
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.