Data Structures & AlgorithmsModerateCAT · TCS NQT

Problem: Five people (including Alice and Bob) stand in a row. In how many arrangements do Alice and Bob stand next to each other?

  1. A. 48
  2. B. 24
  3. C. 120
  4. D. 8

Correct answer: A. 48

Glue Alice and Bob into one block: 4! arrangements × 2 internal orders = 48. Forgetting the internal order gives 24, 120 is every arrangement, and 4 adjacent slots × 2 orders = 8 forgets to arrange the other three.

More Coding Interview Problems questions

Exams that ask this topic