Menu

3561. Resulting String After Adjacent Removals
πŸ“°

3561. Resulting String After Adjacent Removals

DEV Community: phpΒ·MD ARIFUL HAQUEΒ·about 6 hours ago
#CDoA8JVS
#devto#dev#string#example#input
Long article (911 words) β€” no AI summary yet.
Reading 0:00
15s threshold

3561. Resulting String After Adjacent Removals

Difficulty: Medium

Topics: Senior , String , Stack , Simulation , Weekly Contest 451

You are given a string s consisting of lowercase English letters.

You must repeatedly perform the following operation while the string s has at least two consecutive characters:

Remove the leftmost pair of adjacent characters in the string that are consecutive in the alphabet, in either order (e.g., 'a' and 'b' , or 'b' and 'a' ).

Shift the remaining characters to the left to fill the gap.

Return the resulting string after no more operations can be performed .

Note: Consider the alphabet as circular, thus 'a' and 'z' are consecutive.

Example 1:

Input: s = "abc"

Output: "c"

Explanation:

Remove "ab" from the string, leaving "c" as the remaining string.

No further operations are possible.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.