Problem · Hash Table

Phone Spam Report Counter

Learn this problem
EasyPinterest logoPinterestFULLTIMEONSITE INTERVIEW

Problem statement

Process a finite ordered sequence of operations for a phone spam-report counter.

  • REPORT phoneNumber records one new spam report for phoneNumber. Repeated reports are distinct events, so each operation increments that number's count by one.
  • COUNT phoneNumber returns the current number of reports for phoneNumber. A number that has not been reported returns 0.

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 phoneNumber or COUNT phoneNumber.
  • Every phoneNumber contains between 1 and 32 decimal digits.
  • The count for every phone number fits in a signed 32-bit integer.

More Pinterest problems

drafts saved locally
public int[] countSpamReports(String[] operations) {
    // Write your code here.
}
operations["REPORT 4155550100","REPORT 4155550100","COUNT 4155550100","COUNT 2125550199"]
expected[2,0]
checking account