A row of solar panels is described by a string of characters D (deployed) and S (stowed). A single maintenance action selects two adjacent panels that are both currently deployed (a "DD" pair) and folds them, turning both into S simultaneously; every other panel in the row is left untouched.
Given the current row, determine every distinct row configuration that results from performing exactly one such action. If no adjacent deployed pair exists, no action is possible.
A single line containing the current row: a string of length between 1 and 500, consisting only of the characters D and S.
Print one resulting configuration per line, ordered by the starting index (0-indexed, left to right) of the pair that was folded to produce it. If no action is possible, print nothing.
D and S.Example 1
Input
DDSD
Expected
SSSD
Explanation
The only adjacent pair of deployed panels is at index 0 ("DD"). Folding it turns the row into "SS" + "SD" = "SSSD", which is the only reachable configuration.
Example 2
Input
DDDD
Expected
SSDD DSSD DDSS
Explanation
There are three adjacent "DD" pairs, at indices 0, 1, and 2. Folding index 0 gives "SSDD"; folding index 1 gives "DSSD"; folding index 2 gives "DDSS". All three are printed in that order.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →