BackmediumStrings Swiggy Salesforce

Galactic Morse Encoder Solution

Problem Statement

Given a string s, determine the length of the longest signal sequence where characters alternate between being dots (represented as 'X') and dashes (represented as 'Y').

Example 1
Input
XY
Output
2

Explanation: Step-by-step: with input XY, we do A then B, giving output 2. The longest alternating sequence is XY, and its length is 2.

Example 2
Input
XYX
Output
3

Explanation: Step-by-step: with input XYX, we do A then B then A, giving output 3. The longest alternating sequence is XYX, and its length is 3.

Constraints

  • 1 <= signal length <= 1000
  • Signal sequence consists only of 'X' (dot) and 'Y' (dash) characters.
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