dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
79 lines
1.7 KiB
Markdown
79 lines
1.7 KiB
Markdown
---
|
|
id: 69f35a5bb823ed620fcb7cbb
|
|
title: "Challenge 282: Sleep Debt"
|
|
challengeType: 29
|
|
dashedName: challenge-282
|
|
---
|
|
|
|
# --description--
|
|
|
|
Given an array of hours slept each night leading up to today, and a target number of hours per night, return how many hours of sleep you need tonight to eliminate your sleep debt.
|
|
|
|
- Include tonight's hours in the total time needed to catch up.
|
|
- If you've slept enough to cover tonight's target or more, return `0`.
|
|
|
|
# --hints--
|
|
|
|
`sleep_debt([6, 6, 6, 6, 6, 6], 8)` should return `20`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(sleep_debt([6, 6, 6, 6, 6, 6], 8), 20)`)
|
|
}})
|
|
```
|
|
|
|
`sleep_debt([6, 7, 8, 4, 8, 6], 7)` should return `10`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(sleep_debt([6, 7, 8, 4, 8, 6], 7), 10)`)
|
|
}})
|
|
```
|
|
|
|
`sleep_debt([10, 10, 9, 10, 9, 11], 9)` should return `4`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(sleep_debt([10, 10, 9, 10, 9, 11], 9), 4)`)
|
|
}})
|
|
```
|
|
|
|
`sleep_debt([8, 7, 6, 7, 6, 8], 6)` should return `0`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(sleep_debt([8, 7, 6, 7, 6, 8], 6), 0)`)
|
|
}})
|
|
```
|
|
|
|
`sleep_debt([8, 9, 10, 9, 10, 7], 7)` should return `0`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(sleep_debt([8, 9, 10, 9, 10, 7], 7), 0)`)
|
|
}})
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```py
|
|
def sleep_debt(hours_slept, target_hours):
|
|
|
|
return hours_slept
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```py
|
|
def sleep_debt(hours_slept, target_hours):
|
|
debt = (len(hours_slept) + 1) * target_hours - sum(hours_slept)
|
|
return max(0, debt)
|
|
```
|