BackmediumStrings Uber

Intergalactic Communication Solution

Problem Statement

Create a function to analyze signals received from space stations. A signal is valid if it contains an equal number of 'x's and 'y's and does not have any consecutive repeating characters. Write a function to identify and count the total number of valid signals within a given sequence of signals.

Example 1
Input
['xyxyx', 'xyxyy', 'xyx', 'yxyx', 'xyxyxyx', 'xyxxyxyx']
Output
2

Explanation: Step-by-step: 1. Check if the signal 'xyxyx' has equal number of 'x's and 'y's. It does, so it's valid. 2. Check if the signal 'xyxyx' has consecutive repeating characters. It does not, so it's valid. 3. Repeat steps 1 and 2 for all signals. 4. Count the total number of valid signals.

Example 2
Input
['xyxyx', 'xyxyy', 'xyx', 'yxyx', 'xyxyxyx', 'xyxxyxyx', 'xxxyy']
Output
2

Explanation: Step-by-step: 1. Check if the signal 'xyxyx' has equal number of 'x's and 'y's. It does, so it's valid. 2. Check if the signal 'xyxyx' has consecutive repeating characters. It does not, so it's valid. 3. Repeat steps 1 and 2 for all signals. 4. Count the total number of valid signals.

Constraints

  • 1 <= length of the signal sequence <= 1000
  • The signal sequence contains only 'x's and 'y's.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free