Given a string s, reverse the string according to the following rules:


	All the characters that are not English letters remain in the same position.
	All the English letters (lowercase or uppercase) should be reversed.


Return s after reversing it.

&nbsp;
Example 1:
Input: s = "ab-cd"
Output: "dc-ba"
Example 2:
Input: s = "a-bC-dEf-ghIj"
Output: "j-Ih-gfE-dCba"
Example 3:
Input: s = "Test1ng-Leet=code-Q!"
Output: "Qedo1ct-eeLg=ntse-T!"

&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 100
	s consists of characters with ASCII values in the range [33, 122].
	s does not contain '\"' or '\\'.


class Solution:
    def reverseOnlyLetters(self, s: str) -> str:
        st,sp=[],[]
        for i,ch in enumerate(s):
            if ch.isalpha():
                st.append(ch)
            else:
                sp.append([i,ch])
        st=st[::-1]
        for i in sp:
            st.insert(i[0],i[1])
        return (''.join(st))
class Solution {
    public String reverseOnlyLetters(String s) {
        // converting the string to the charArray...
        char[] ch = s.toCharArray();

        int start = 0;
        int end = s.length()-1;

        // Storing all the english alphabets in a hashmap so that the searching becomes easy...
        HashMap<Character , Integer> hash = new HashMap<>();
        for(int i=0 ; i<26 ;i++){
            hash.put((char)(97+i) , 1);
        }
        for(int i=0 ; i<26 ; i++){
            hash.put((char)(65+i) , 1);
        }

        // using two while loops ..since the constraints are too less thats why we can prefer nested loops approach..
        while(start<end){

            // interating untill start pointer reacher a good character
            while(start<end&&!hash.containsKey(ch[start])){
                start++;
            }
            // iterating untill the end pointer reaches the good character..
            while(end>start&&!hash.containsKey(ch[end])){
                end--;
            }

            // swapping the array elements..
            char temp = ch[start];
            ch[start] = ch[end];
            ch[end] = temp;

            start++;
            end--;
        }

        // converting the charArray to the string again..
        String ans = new String(ch);
        return ans;

        // Time Complexity : O(N) (since the loops will run only till the number of charcters in the string..)
        // Space Complexity : O(N) since we used hashmap..
    }
}
class Solution {
public:
    string reverseOnlyLetters(string s) {
        int a=0,b=s.size()-1;
        for(;a<b;)
        {
            if(((s[a]>='a'&&s[a]<='z')||(s[a]>='A'&&s[a]<='Z'))&&((s[b]>='a'&&s[b]<='z')||(s[b]>='A'&&s[b]<='Z')))
               {
                   char z=s[a];
                   s[a]=s[b];
                   s[b]=z;
                   a++;
                   b--;
               }
               else if(!((s[a]>='a'&&s[a]<='z')||(s[a]>='A'&&s[a]<='Z'))&&((s[b]>='a'&&s[b]<='z')||(s[b]>='A'&&s[b]<='Z')))
                       {
                           a++;
                       }
                       else if(((s[a]>='a'&&s[a]<='z')||(s[a]>='A'&&s[a]<='Z'))&&!((s[b]>='a'&&s[b]<='z')||(s[b]>='A'&&s[b]<='Z')))
                       b--;
                       else{
                           a++;
                           b--;
                       }

    }
        return s;
    }
};
var reverseOnlyLetters = function(s) {
    let valid = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    let arr = s.split('')
    
    let r = arr.length - 1;
    let l = 0;
    
    while (l < r) {
        while (!valid.includes(arr[l]) && l < r) {
            l++;
            continue;
        }
    
        while (!valid.includes(arr[r]) && l < r) {
            r--;
            continue
        }
        
        if (l >= r) break;
        
        [arr[l], arr[r]] = [arr[r], arr[l]];
        l++;
        r--;
    }
    
    
    return arr.join('')
	```
Reverse Only Letters