Skip to content
Discussion options

You must be logged in to vote

We are given a corridor represented as a string of seats ('S') and plants ('P'). We need to divide it into sections such that each section has exactly 2 seats. There are already fixed dividers at the start and end. We can place additional dividers between any two adjacent positions (between indices i-1 and i).

The goal is to count the number of valid ways to place dividers. A section can have any number of plants, but must have exactly 2 seats. Two ways are different if there's at least one position where a divider is placed in one way but not the other.

Key Observations

  1. Total number of seats must be even - If odd, return 0.
  2. Each section must have exactly 2 seats - So we need to pair up …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Dec 14, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Dec 14, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested hard Difficulty
2 participants