Reverse a String | Practice | GeeksforGeeks

You are given a string s. You need to reverse the string.
Example 1:
Input:
s = Geeks
Output: skeeG

Example 2:
Input:
s = for
Output: rof
Your Task:
You only need to complete the function reverseWord() that takes s as parameter and returns the reversed string.
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(1).
Constraints:
1 <= |s| <= 10000
0
dnpanday90in 7 hours
-------- JAVA --------class Reverse{   // Complete the function   // str: input string   public static String reverseWord(String str)   {      StringBuilder s=new StringBuilder();      String[] a=str.split(" ");     for(int i=a[0].length()-1;i>=0;i--){             s.append(str.charAt(i));               }      return s.toString();   }}
0
reshmisanjayanin 6 hours
string reverseWord(string str){   string s="";   for(int i=str.length()-1;i>=0;i--)   {       s+=str[i];   }   return s; //Your code here}
0
mahiagrawal121345 minutes ago
def reverseWord(s):
    return s[::-1]
 
s=Geeks
t=reverseWord(s)
print(t)
0
iamgauravshukla6 hours ago
Easiest Solution and Faster also 👍
def reverseWord(s):   return s[::-1]
-1
nihithreddyr16 hours ago
class Reverse
{
    // Complete the function
    // str: input string
    public static String reverseWord(String str)
    {
       char[] strArray = str.toCharArray();
       reverseCharacterArray(strArray,0,strArray.length-1);
       String reversedWord = new String(strArray);
       return reversedWord;
    }
    public static void reverseCharacterArray(char[] strArray,int startIndex,int endIndex){
        if(startIndex >= endIndex){
            return;
        }
        strArray[startIndex] ^= strArray[endIndex];
        strArray[endIndex] ^= strArray[startIndex];
        strArray[startIndex] ^= strArray[endIndex];
        reverseCharacterArray(strArray,startIndex+1,endIndex-1);
    }
}
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested 
                                    against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code.
                                    On submission, your code is tested against multiple test cases consisting of all
                                        possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as
                                        the final solution code.
You can view the solutions submitted by other users from the submission tab.
Make sure you are not using ad-blockers.
Disable browser extensions.
We recommend using latest version of your browser for best experience.
Avoid using static/global variables in coding problems as your code is tested 
                                against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases in coding problems does not guarantee the 
                                correctness of code. On submission, your code is tested against multiple test cases
                                    consisting of all possible corner cases and stress constraints.