Problem · Hash Table
Count Server Replacements
Learn this problemProblem statement
You have n servers with IDs "s1", "s2", ..., "sn". The system processes a sequence of log entries, where each entry is formatted as:
"<server_id> <status>", wherestatusis either"success"or"error"
For each server, track its consecutive errors:
- If a server records three
"error"logs in a row, it is considered faulty and is replaced. The replacement server keeps the same ID. - After a replacement, that server's consecutive error count resets to
0. - A
"success"log also resets that server's consecutive error count to0.
Your task is to determine the total number of server replacements that occur while processing all log entries.
Function
countServerReplacements(n: int, logs: String[]) → intExamples
Example 1
n = 2logs = ["s1 error", "s1 error", "s2 error", "s1 error", "s1 error", "s2 success"]return = 1More Wells Fargo problems
- Minimum Remaining LengthOA · Seen Feb 2026
- Compressing ArraySeen Dec 2024
- Sum of Compressed Number for All SubarraysSeen May 2024
- Allocate Wells for Fair DistributionSeen Oct 2023
- Count OperationsSeen Aug 2023
- Find Maximum DistanceSeen Aug 2023
- Get SubstringSeen Aug 2023
- Find Last Affected SystemSeen May 2022