K47
Unique Visitor Counter
Problem Statement & Objective
Maintain an accurate count of distinct user visits within sliding operational time intervals.
Function Signature (Python)
unique_visitor_counter(operations: list) -> listInput & Output Contract
Output Rule:'get_hits' işlemlerinin sonuçlarını içeren tam sayı listesi.
System Constraints
1 <= islemler.length <= 10^4
1 <= t <= 10^8
Zaman damgaları artan sırada verilirExample Execution Walkthrough
islemler = [['hit', 1], ['hit', 2], ['hit', 3], ['get_hits', 4], ['hit', 300], ['get_hits', 300], ['get_hits', 301]]
get_hits(4) -> [1, 4] aralığı: 3
get_hits(300) -> [1, 300] aralığı: 4
get_hits(301) -> [2, 301] aralığı (1 düştü): 3
Cevap: [3, 4, 3]Example Test Scenarios (3)
Example 1: Basic Window
Input:
[[["hit",1],["hit",2],["hit",3],["get_hits",4],["hit",300],["get_hits",300],["get_hits",301]]]Expected Output:
[3,4,3]Example 2: Zaman Aşımı
Input:
[[["hit",100],["get_hits",100],["get_hits",399],["get_hits",400]]]Expected Output:
[1,1,0]Example 3: Boş Sayaç
Input:
[[["get_hits",5]]]Expected Output:
[0]