Count Faults
Learn this problemProblem statement
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
countFaults(n: int, logs: String[]) → int
Complete the function countFaults in the editor 👉.
countFaults has the following parameter:
int n: the number of serversString logs[m]: the application logsReturns
int: the number of times servers were replaced
Examples
Example 1
n = 2logs = ["s1 error", "s1 error", "s2 error", "s1 error", "s1 error", "s2 success"]return = 1
Constraints
1 <= n <= 2001 <= 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 💛💚🧡💖)More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026