The hidden rune
- O(n) · Medium
- Full plan
- Python
- JavaScript
- strings
- booleans
- loops
Problem
No spell in Valdoria is ever written in plain sight: it is hidden inside a long scroll, among other letters. The apprentice gets a spell and a scroll, and wants to know if the spell is in there.
Write a function that takes spell and scroll, two texts of lowercase letters with no spaces, and returns true if you can pick letters from the scroll, left to right, until you read the whole spell in order, and false otherwise. The letters don't have to be next to each other, but each letter of the scroll can be used only once: "ooo" is not in "moonlit", which only has two o's.
For example, "sun" is hidden in "assuming": the s, the u and the n show up in that order. "nus" is not, because after the n no u is left. An empty spell is always hidden, even when the scroll is empty. A spell with letters is never hidden in an empty scroll.
Examples
The one in the example
"sun", "assuming" → true
The letters backwards
"nus", "assuming" → false
All next to each other
"fire", "fire" → true
One letter is missing
"light", "lift" → false
Scroll left over at the end
"arm", "farmhouse" → true
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def is_hidden(spell, scroll):
passJavaScript
function isHidden(spell, scroll) {
}It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.