Lesson 14 of 24

set, stack, queue and priority_queue

11 min 35 XP

set holds unique sorted values. stack is last-in-first-out (LIFO), queue is first-in-first-out (FIFO), and priority_queue always keeps the largest on top.

Example: edit me and press Run

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.

Balanced brackets is the classic stack interview question: push opening brackets; on a closing bracket, check the top matches and pop.

Challenge

+35 XP

Read a string of brackets ((), [], {}). Print "Balanced" if every bracket is closed in the right order, otherwise "Not balanced". Input: {[()]} → Output: Balanced

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.