← Questions

Penalty for shutting down a server from its uptime log

0
StripeCodingLast asked Sep 2023

A server's log has one entry per hour, 0 when it was up and 1 when it was down, separated by spaces. If the server is removed just before hour k, the penalty is the number of hours it was down while still installed plus the number of hours it would have been up after removal. Given the log and k, return the penalty. Handle k at either end of the log and explain how prefix counts let you evaluate any k in constant time.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding