Given a string, that contains special character together with alphabets (‘a’ to ‘z’ and ‘A’ to ‘Z’), reverse the string in a way that special characters are not affected.



Examples:



Input: str = "a,b$c" Output: str = "c,b$a" Note that $ and , are not moved anywhere. Only subsequence "abc" is reversed Input: str = "Ab,c,de!$" Output: str = "ed,c,bA!$"

Java Code:-






class test{
public static void main(String[] args){
String a="a,b$c";
int len=a.length();
char arr[]=new char[len];
char arr1[]=new char[len];
for(int i=0;i
arr[i]=a.charAt(i);
}
int templen=len-1;
for(int i=0;
if(Character.isLetter(arr[i])){
for(int j=templen;j>0;j--){
if(Character.isLetter(arr[j])){
//System.out.println(arr[i]+"=="+arr[j]);
char temp=arr[j];
arr[j]=arr[i];
arr[i]=temp;
templen=j-1;
break;
}
}
}
}
for(int i=0;i
System.out.println(arr[i]+"\t");
}
}
}