Algorithms and Data Structures · Junior · Question 19 of 75

Which task is a natural fit for a stack?

Explanation

Push every opening bracket; on a closing bracket pop and check that it matches. The last opened bracket must be closed first, which is exactly LIFO. Serving requests in order is a queue.

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 19

Test yourself

Take the Algorithms and Data Structures · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz