/293. Generate All Valid String Flips

293. Generate All Valid String Flips

Easy
Strings65% acceptance

Given a string consisting of only the characters + and -, generate all possible strings after flipping any pair of consecutive + characters to --. Return the list of all possible resulting strings. Each flip must change exactly two consecutive + to --.

Example 1

Input: ++--+++

Output: [----+++,++----+,++--+--]

Explanation: Flipping each pair of consecutive + in positions 0-1, 4-5, and 5-6 yields the three possible strings.

Example 2

Input: ++++

Output: [--++,+--+,++--]

Explanation: Flipping pairs at positions 0-1, 1-2, and 2-3.

Constraints

  • 1 <= len(input_string) <= 100
  • input_string consists only of + and - characters
Python (current runtime)

Case 1

Input: '+-+-+++'

Expected: ['+-+-+--','+-+---+']

Case 2

Input: '--++--'

Expected: ['------']

Case 3

Input: '+++'

Expected: ['--+','+--']

Case 4

Input: '--+--'

Expected: []