EX_03/level-2/rip
2025-10-05 17:10:55 +01:00
..
Makefile added level-1 2025-09-23 08:41:21 +01:00
README.md Edited README's, added broken_gnl exercise, LICENSE and main README 2025-10-05 17:10:55 +01:00
rip.c added level-1 2025-09-23 08:41:21 +01:00
subject.txt added level-1 2025-09-23 08:41:21 +01:00

The Parentheses Balancing Problem (RIP Exercise)

What is this exercise about?

Imagine you have a string of parentheses like this: "(()".

Think of parentheses like doors in a building:

  • ( is like opening a door
  • ) is like closing a door

For everything to work properly, every door you open must have a matching door that closes it!

The Problem

Sometimes we get strings where the doors don't match properly. For example:

  • "(((" - We opened 3 doors but never closed any!
  • "())" - We opened 1 door, closed 1 door, but then tried to close another door that was never opened!

Our job is to fix these strings by removing the minimum number of parentheses (but replacing them with spaces instead of deleting them completely).

Real-World Example

Let's say you have: "(()"

This means:

  1. Open door 1: (
  2. Open door 2: (
  3. Close door 2: )
  4. But door 1 is still open!

To fix this, we need to either:

  • Remove one of the opening doors: () (remove first ()
  • Or remove one of the opening doors: ( ) (remove second ()