Problem · Hash Table
Phone Spam Report Counter
Learn this problemProblem statement
Process a finite ordered sequence of operations for a phone spam-report counter.
REPORT phoneNumberrecords one new spam report forphoneNumber. Repeated reports are distinct events, so each operation increments that number's count by one.COUNT phoneNumberreturns the current number of reports forphoneNumber. A number that has not been reported returns0.
Return the integer results of all COUNT operations in encounter order. A REPORT operation produces no result. There is no deletion or time window.
Function
countSpamReports(operations: String[]) → int[]Examples
Example 1
operations = ["REPORT 4155550100","REPORT 4155550100","COUNT 4155550100","COUNT 2125550199"]return = [2,0]The first number receives two reports. The second number has never been reported.
Example 2
operations = ["COUNT 7","REPORT 7","COUNT 7","REPORT 8","REPORT 7","COUNT 8","COUNT 7"]return = [0,1,1,2]Counts are independent per phone number and reflect only preceding REPORT operations.
Example 3
operations = ["REPORT 999","COUNT 999","COUNT 999"]return = [1,1]A count query does not mutate the stored count.
Constraints
1 <= operations.length <= 100000.- Every operation is exactly
REPORT phoneNumberorCOUNT phoneNumber. - Every
phoneNumbercontains between1and32decimal digits. - The count for every phone number fits in a signed 32-bit integer.