Skip to content
This repository was archived by the owner on Oct 14, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Programming/Kotlin/DesignHitCounter/DesignHitCounter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.testapp

fun main(){
//Making an input as the question suggests doesn't really make any sense.
val hitCounter = HitCounter()
hitCounter.hit(1)
hitCounter.hit(2)
hitCounter.hit(3)
println(hitCounter.getHits(4))
hitCounter.hit(300)
println(hitCounter.getHits(300))
println(hitCounter.getHits(301))
}

class HitCounter {
private val hits = arrayListOf<Int>()

fun hit(timestamp: Int) = hits.add(timestamp)

fun getHits(timestamp: Int) : Int = hits.count {
it in (timestamp - 300 + 1)..timestamp
}
}