aditya109 / git-osp-for-beginners

A GitHub Repository to encourage and involve beginners in Open Source Contributions
GNU General Public License v3.0
104 stars 250 forks source link

Design Hit Counter [Kotlin-Solution required] #549

Open nitishanand99 opened 2 years ago

nitishanand99 commented 2 years ago

Question :

Design a hit counter which counts the number of hits received in the past 5 minutes (i.e., the past 300 seconds).

Your system should accept a timestamp parameter (in seconds granularity), and you may assume that calls are being made to the system in chronological order (i.e., the timestamp is monotonically increasing). Several hits may arrive roughly at the same time.

Implement the HitCounter class:

Example 1:

Input ["HitCounter", "hit", "hit", "hit", "getHits", "hit", "getHits", "getHits"] [[], [1], [2], [3], [4], [300], [300], [301]] Output [null, null, null, null, 3, null, 4, 3]

Explanation : HitCounter hitCounter = new HitCounter(); hitCounter.hit(1); // hit at timestamp 1. hitCounter.hit(2); // hit at timestamp 2. hitCounter.hit(3); // hit at timestamp 3. hitCounter.getHits(4); // get hits at timestamp 4, return 3. hitCounter.hit(300); // hit at timestamp 300. hitCounter.getHits(300); // get hits at timestamp 300, return 4. hitCounter.getHits(301); // get hits at timestamp 301, return 3.

nitishanand99 commented 2 years ago

Hello, again @aditya109! Can you please assign me this issue?

aditya109 commented 2 years ago

Hi @nitishanand99 ! I have assigned this issue to you. Before raising a PR, please take a look at CONTRIBUTING.md and follow the guidelines. That is all. Happy hacking !