The letters left over
- O(1) · Trivial
- Free
- Python
- JavaScript
- strings
- operations
Problem
A message can't go over a certain number of letters. Write a function that takes the message and the limit, and returns how many letters you have to drop so it fits: with "hello world" and a limit of 5, six are left over. If it fits exactly, or if there's room to spare, there's nothing to drop: you return 0, never a negative number.
Examples
"hello world", 5 → 6
Room to spare
"hello", 10 → 0
Right at the limit
"hello", 5 → 0
"a long message", 8 → 6
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def extra_letters(text, limit):
passJavaScript
function extraLetters(text, limit) {
}Solve this challenge
It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.