Count Server Replacements
Updated
Problem 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>", and status is 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.
Determine the total number of server replacements that occur while processing all log entries.
Custom testing format
- The first line contains the integer
n. - The next line contains the integer
m, the size oflogs. - Each of the next
mlines contains one string element oflogs.
Function
countFaults(n: int, logs: String[]) → intExamples
Example 1
n = 2logs = ["s1 error", "s1 error", "s2 error", "s1 error", "s1 error", "s2 success"]return = 1- Server
s1logs its first error:[error]. - Server
s1logs its second error:[error, error]. - Server
s2logs its first error:[error]. - Server
s1logs its third consecutive error:[error, error, error], so it is replaced. - The new server
s1logs its first error:[error]. - Server
s2logs a success, so its consecutive-error record resets.
Only server s1 is replaced, and it is replaced once.
Constraints
1 <= n <= 2001 <= logs.length <= 2 * 10^4
More Akuna Capital Online Assessment questions
- Delivery Management SystemOA · Seen Nov 2026
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximum Remaining Drone PowerOA · Seen Nov 2026
- Rolling MetricsOA · Seen Oct 2026
- Vowel Substring GameOA · Seen Sep 2026
- Competitive ForagingOA · Seen Sep 2026
- Binary CircuitOA · Seen Sep 2026
- Items SortOA · Seen Sep 2026
- Minimize Malware Spread by Removing a NodeOA · Seen Sep 2026
- K Smallest SubstringOA · Seen Sep 2026
Similar questions at other companies
- Branch with the Most FilesCapital One · OACapital One interview questions
- Per-User Sliding-Window Rate LimiterPayPal · OAPayPal interview questions
- Basic Item DiscountsPalantir · OAPalantir interview questions
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
- Student and Course EnrollmentWells Fargo · OAWells Fargo interview questions
- Network Endpoint or Cycle BoundaryOpenAI · OA · PHONE SCREENOpenAI interview questions
- Assign Server Numbers by TypeOura · OA
- Filter Transaction Logs and Calculate Reliability MetricsStripe · OAStripe interview questions
- Calculate Net ProfitJP Morgan Chase · OAJP Morgan Chase interview questions
- Get Total RequestsAmazon · OA
Akuna Capital interview experiences
- Akuna Capital Quant Trader and QR Interviews: 5 Experiences
- Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
- Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
- Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
- Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
- Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)