6 kyu
Longest Alternating Substring
144saudiGuy
Description:
Task
Given a string of digits, return the longest substring with alternating odd/even
or even/odd digits
. If two or more substrings have the same length, return the substring that occurs first.
Examples
longest_substring("225424272163254474441338664823") ➞ "272163254"
# substrings = 254, 272163254, 474, 41, 38, 23
longest_substring("594127169973391692147228678476") ➞ "16921472"
# substrings = 94127, 169, 16921472, 678, 476
longest_substring("721449827599186159274227324466") ➞ "7214"
# substrings = 7214, 498, 27, 18, 61, 9274, 27, 32
# 7214 and 9274 have same length, but 7214 occurs first.
longest_substring("20") ➞ "2"
longest_substring("") ➞ ""
Input Constraints
- 0 <= len(digits) <= 10^5
Algorithms
Logic
Regular Expressions
Strings
Similar Kata:
Stats:
Created | Aug 15, 2023 |
Published | Aug 15, 2023 |
Warriors Trained | 259 |
Total Skips | 9 |
Total Code Submissions | 754 |
Total Times Completed | 144 |
Python Completions | 144 |
Total Stars | 7 |
% of votes with a positive feedback rating | 95% of 41 |
Total "Very Satisfied" Votes | 37 |
Total "Somewhat Satisfied" Votes | 4 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 21 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |