Ctrl K

Both Cases Stretch

Easy
Call a string **paired** if every letter that occurs in it occurs in both lowercase and uppercase. For example, cCdDd is paired, while cCd is not, because it has no uppercase D. Given a string text of English letters, find its longest contiguous piece that is a paired string and return it. If several pieces share the maximum length, return the one that starts first. If there is no paired piece at all, return an empty string.
Example 1
text="xKkqQkz" → 'KkqQk'

In KkqQk the letter k appears as both K and k, and q as both q and Q. Neither x nor z can be added, since their other case is missing.

Example 2
text="aAxbB" → 'aA'

Both aA and bB qualify with length 2, so the one that starts earlier is returned.

Example 3
text="Mn" → ''

No letter has its pair, so the answer is the empty string.

Constraints
  • 1 ≤ len(text) ≤ 100
  • text consists of lowercase and uppercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsRecurring Gene Windows MediumEvery Letter at Least k Times MediumShuffle Into a Palindrome EasyThe Sneaked-In Letter EasyWords From Working Keys Easy
loading Python…
Input
text="xKkqQkz"
Expected
'KkqQk'

Run checks the first 3 tests in your browser. Submit checks all 125 tests on the server, hidden ones included.