Opening your workspace…
Workspace/Coding room
Opening your workspace…
Teemo is planting shrooms in the brush along top lane. His map marks brush tiles with 'B' and open ground with '.'. Each enemy route crosses every tile from start to end, inclusive. What’s the fewest shrooms Teemo needs to plant so that every route crosses at least one? The routes are possible paths for the next enemy. Return -1 if any route misses the brush entirely.
"B.B.B.B", [[0,3],[1,4],[3,6]]Output2Plant on tile 2 for the first two routes and tile 4 for the last. All three routes share only tile 3, which is open ground, so one shroom cannot cover them all.
".BB..", [[0,2],[2,2],[2,4]]Output1The single-tile route forces Teemo to plant on tile 2. Both other routes cross that tile too.
Handle routes by their right endpoint and plant at the rightmost available brush.
function solve(lane, routes) { // 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.