Opening your workspace…
Workspace/Coding room
Opening your workspace…
You run the Lost and Found at Luigi’s Mansion. Before dawn, Luigi has to put every loose item on the counter. He reaches into a suitcase and pulls out a handbag. The handbag contains a coin purse. “I’d use both hands,” he says, as the Poltergust hose starts crawling away again.
The inventory scan records the packing order from left to right. Outside ghost chatter, [ opens a bag, ] closes it, and * marks one item. < starts chatter, which ends at the first uncanceled >. Inside chatter, ! cancels the next character, even another !. Ignore everything inside chatter. Luigi retrieves one item per trip and zips every bag shut afterward. Return the total number of times he must unzip a bag. An item on the counter needs no unzipping.
"*[*[**]]"Output5The counter item needs no bag opened. The next item needs one. Each of the two innermost items needs both bags opened, for a total of 0 + 1 + 2 + 2 = 5.
"[<mine!>**>[*]*]"Output3The ghost cancels the first >, so both stars after it belong to the chatter. Luigi opens two bags for the item in the inner bag, then reopens the outer bag for the last item.
[, ], *, and < can occur. Every bag has a matching closing bracket, and bags nest correctly.! inside chatter has a following character to cancel.Track open bags outside chatter. Inside chatter, cancellation skips precisely one character.
function solve(scan) { // 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.