Dsa
Dynamic Programming
Easy
Longest Gold Sequence
You are given a string consisting of lowercase letters. Your task is to find the length of the longest sequence of characters in which each character appears consecutively and any two consecutive characters must differ by exactly 1 in their ASCII values. For example, 'abc' and 'cba' would both be valid sequences.
Input format:
The first line contains the string s (1 <= len(s) <= 100).
Output format:
Print an integer representing the length of the longest valid sequence.
Example:
Input:
bcaabc
Output:
4
Key concepts
dynamic_programmingsequence
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now