Skip to content

Instantly share code, notes, and snippets.

@kimji1
Last active August 6, 2020 05:17
Show Gist options
  • Select an option

  • Save kimji1/463edda90aa451769f046dde011254c8 to your computer and use it in GitHub Desktop.

Select an option

Save kimji1/463edda90aa451769f046dde011254c8 to your computer and use it in GitHub Desktop.
fun pickingNumbers(a: Array<Int>): Int {
var ret = Int.MIN_VALUE
val map = hashMapOf<Int, Int>()
a.forEach { i ->
map[i] = a.filter { it == i }.size
}
for (i in map.keys) {
val value = map[i]!!.plus(map.getOrDefault(i - 1, 0))
if (value > ret) {
ret = value
}
}
return ret
}
fun main(args: Array<String>) {
val n = readLine()!!.trim().toInt()
val a = readLine()!!.trimEnd().split(" ").map { it.toInt() }.toTypedArray()
val result = pickingNumbers(a)
println(result)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment