__Whisper's blog

By __Whisper, history, 2 hours ago, In English

Hi guys, I got stuck in a problem and i want to make test generation but idk how to generate a regular bracket does anyone know how to do that?

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
5 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Maintain stack. Randomly choose an operation to add a forward bracket or reverse bracket. When you add a forward bracket, add it to the stack. Add a reverse bracket only if there is at least one forward bracket in the stack. And in that case remove one forward bracket from the stack. In order to maintain a size limit, note that a bracket sequnce of size 2n has exactly n forward brackets. So use it to restrict the length of the sequence.