Calculate Server Shutdown Penalty
Updated
Problem statement
A server log contains one state per time slot. The states are separated by whitespace:
0means the server was up and functioning during that slot.1means the server was down during that slot.
You remove the server immediately before slot removedTime. Slots with indexes smaller than removedTime occur while the server is still installed; later slots occur after removal.
The penalty is the number of down slots before removal plus the number of up slots at or after removal. Return that total penalty.
Function
calculateShutdownPenalty(logs: String, removedTime: int) → intExamples
Example 1
logs = "0 0 0 1 0 0"removedTime = 3return = 2No down slot occurs before removal. Two up slots occur after it, so the penalty is 2.
Example 2
logs = "1 1 0 0"removedTime = 2return = 4The two down slots before removal and the two up slots after removal each contribute one penalty point.
Example 3
logs = "0 1 1"removedTime = 0return = 1The server is removed before every slot. Only the first slot was an up slot, so only it is penalized.
Constraints
1 <= n <= 200000, wherenis the number of log states.- Every state is exactly
0or1, separated by one or more whitespace characters. 0 <= removedTime <= n.
More Stripe Phone Screen questions
- Business Account KYC Verification — Parts 1–5PHONE SCREEN · Seen Nov 2026
- Financial Account LedgerOA · PHONE SCREEN · Seen Nov 2026
- Merchant Matching, Parts 1–2: Shared Fields and Weighted ThresholdsPHONE SCREEN · Seen Nov 2026
- Parse Boolean Rule ExpressionsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Merchant Payout Scheduler, Part 2: Per-Merchant SchedulesPHONE SCREEN · Seen Nov 2026
- Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesPHONE SCREEN · Seen Nov 2026
- Render a Task Tree from CSV RowsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Invoice / Payment ReconciliationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Linked Merchants Within Two HopsPHONE SCREEN · Seen Nov 2026
- Portfolio Valuation, Part 1PHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Wallet Balance on a Selected DayBharatPe · PHONE SCREEN
- Instrument Stack Language JumpsJane Street · PHONE SCREENJane Street interview questions
- Schedule Buffered Video PlaybackNuro · PHONE SCREENNuro interview questions
- Weighted Lottery WinnersAmazon · ONSITE INTERVIEW
- Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
- Array Challenge (QR Intern)Akuna Capital · OAAkuna Capital interview questions
- Range Negation UpdatesJP Morgan Chase · OAJP Morgan Chase interview questions
- Data UpdatesExpedia · OAExpedia interview questions
- Hall of Shifting TilesAdobe · OAAdobe interview questions
- Prefix Scores With the Running MaximumC3.ai · OAC3.ai interview questions
Interview reports that mention this question
- Stripe SWE Intern Technical Screen Questions Guide
- Stripe SWE Intern Bank OA and Closing Hours: 1 Experience
- Stripe MLE Intern Server-Log Screen: 1 Experience
- Stripe Seattle SWE Intern Logs, Limiter, Bikemap: 1 Experience
- Stripe SWE Intern Closing-Penalty Screen: 1 Experience
- Stripe MLE Intern Capital and Shutdown Rounds: 1 Experience