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
1.7 KiB
1.7 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 69f35a5bb823ed620fcb7cbb | Challenge 282: Sleep Debt | 29 | 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.
({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.
({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.
({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.
({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.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(sleep_debt([8, 9, 10, 9, 10, 7], 7), 0)`)
}})
--seed--
--seed-contents--
def sleep_debt(hours_slept, target_hours):
return hours_slept
--solutions--
def sleep_debt(hours_slept, target_hours):
debt = (len(hours_slept) + 1) * target_hours - sum(hours_slept)
return max(0, debt)