FastPrepFastPrep
Problem Brief

Count Faults

OA
See Amazon online assessment and hiring insights

Implement a prototype service to automate the detection and replacement of faulty servers to improve the availabity of an application.

There are n servers with its s1, s2,...,sn, and an array of strings, logs, of size m. Log format is "<server_id> <success/error>", the id of the server and the status of the processed request. If a perticular server id logs an error for three consecutive requests, it is considered faulty and is replaced with a new server with the same id.

Given n and athe array logs, find the number of times a faulty server was replace.

Function Description

Complete the function countFaults in the editor πŸ‘‰.

countFaults has the following parameter:

  • int n: the number of servers
  • String logs[m]: the application logs
  • Returns

    int: the number of times servers were replaced

    1Example 1

    Input
    n = 2, logs = ["s1 error", "s1 error", "s2 error", "s1 error", "s1 error", "s2 success"]
    Output
    1
    Explanation
    Example 1 illustration
    s1 was replaced one time. So output should be 1.

    Constraints

    Limits and guarantees your solution can rely on.

  • 1 <= n <= 200
  • 1 <= m <= 2 * 104 (The source image is too blurry. It looked like 104 to me. If you find it incorrect, please let me know! Many thanks in advance πŸ’›πŸ’šπŸ§‘πŸ’–)
  • public int countFaults (int n, String[] logs) {
      // write your code here
    }
    
    Input

    n

    2

    logs

    ["s1 error", "s1 error", "s2 error", "s1 error", "s1 error", "s2 success"]

    Output

    1

    Sign in to submit your solution.