Reverse Only Alphabetical (Easy)

Good morning! Here's our prompt for today.

You may see this problem at Amazon, Flipkart, Jfrog, Squarespace, Netskope, Mcafee, Sailpoint, and Expedia.

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).
JAVASCRIPT
OUTPUT
Results will appear here.