Skip to content

Instantly share code, notes, and snippets.

@alexnikol
Created June 30, 2020 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexnikol/32ca2d8f323d612f281ddf331b898368 to your computer and use it in GitHub Desktop.
Save alexnikol/32ca2d8f323d612f281ddf331b898368 to your computer and use it in GitHub Desktop.
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