Opening your workspace…
Workspace/Coding room
Opening your workspace…
A moon snail has curled up in the middle of the road. It won’t budge until it drinks one drop of each of its favorite colors. You have a teacup, and a rain sprite tells you what color each drop will be, in order.
You can put the cup out just before any drop and take it back after any drop. It catches every drop in between. Extra drops are fine, even in colors the snail doesn’t need.
What’s the fewest drops you can catch and still give the snail every color it wants? Return -1 if the rain won’t provide them all.
["blue","gray","red","gold","blue"], ["red","gold","blue"]Output3Catch the last three drops. Each has a different favorite color, so three drops is as short as possible.
["red","gray","blue"], ["red","blue"]Output3The gray drop falls between the red and blue drops, so it goes in the cup too.
Shrink the window from the left while every favorite color is present.
function solve(rain, favorite_colors) { // Write your solution here. }
Tab inserts two spaces. Shift+Tab outdents. Use the arrow keys and Tab to choose a suggestion. Press Escape, then Tab, to leave the editor. Press Control or Command with apostrophe to run samples or with Enter to submit.