Skip to content

delimitersoup

bradendubois edited this page Nov 24, 2021 · 8 revisions

Delimiter Soup

ID: delimitersoup

Difficulty: 2.2

CPU Time: 1 second

Memory: 1024 MB

Solution

Create a mapping between the pairs of braces: "(" to ")", etc. And when we read each character, do nothing if it's a space, push the character if it's a left bracket; if it's a right bracket, pop the top of the stack. If the stack is actually empty, or they do not match, output the read bracket and index / number read.

Clone this wiki locally