Mark As Completed Discussion

Good afternoon! Here's our prompt for today.

Reversing Only Alphabetical Characters in a String

Description

The Problem Statement

You are provided with a string that's a blend of alphabetic and non-alphabetic characters. Think of a beach where you find both shells (a-Z) and other things like plastic wrappers or dollar bills ($, !, etc.). For example, you might get:

TEXT
1'sea!$hells3'

Your mission, should you choose to accept it, is to flip only the alphabetical shells while keeping the other items ($, !, etc.) in their original positions.

For example, when calling:

TEXT
1reverseOnlyAlphabetical('sea!$hells3');

You should expect the output to be:

TEXT
1'sll!$ehaes3'

Constraints to Consider

  • String Length: The length of the given string is up to 100,000 characters.
  • Character Set: You'll be working with ASCII characters.
  • Time Complexity: Aim for a time complexity of O(n).
  • Space Complexity: Aim for a space complexity of O(n).

Try to solve this here or in Interactive Mode.

How do I practice this challenge?

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Here's a video of us explaining the solution.

To change the speed of the video or see it in full screen, click the icons to the right of the progress bar.

Here's how we would solve this problem...

How do I use this guide?