How many stack outputs?

The elements 1,2,3,41,2,3,4 are pushed onto a stack in that order. Between pushes you may pop any number of times (including zero), and each popped element is appended to an output sequence. How many distinct output sequences are achievable?

Show hints (2)+
  1. A valid sequence corresponds to a balanced arrangement of pushes and pops.
  2. These are counted by the Catalan numbers 1,1,2,5,14,…1,1,2,5,14,\dots

Answer

Reveal answer →

14

Create a free account to see the full worked solution and track your progress.

Interview format: Numerical Reasoning Tests, Trading Aptitude Tests

Related questions