Java Strings | Set 1 | Practice | GeeksforGeeks

Given two strings S1 and S2 as input. Your task is to concatenate two strings and then reverse the string. Finally print the reversed string.

Example 1:
Input: S1 = "Geeks" , S2 = "forGeeks"
Output: "skeeGrofskeeG" 
Explanation: Concatenating S1 and S2 to 
get "GeeksforGeeks" then reversing it to 
"skeeGrofskeeG".

Example 2:
Input: S1 = "Practice" , S2 = "Geeks"
Output: "skeeGecitcarP"
Explanation: Concatenating S1 and S2 to
get "PracticeGeeks" then reversing it to
"skeegecitcarP".

Your Task:  
You dont need to read input or print anything. Complete the function conRevstr() which takes S1 and S2 as input parameter and returns the sting final_s after concatenating and reversing.

Expected Time Complexity: O(|S1| + |S2|)
Expected Auxiliary Space: O(|S1| + |S2|)

Constraints:
1<= |S1| <=1000
1<= |S2| <=1000
0
shevil21 hours ago
string conRevstr(string S1, string S2) {
       S1+=S2;
       reverse(S1.begin(),S1.end());
       return S1;
}
0
mayank180919991 week ago
  string conRevstr(string S1, string S2) {
        // code here
        string S=S1+S2;
        int j=0;
        string res="";
        for(int i=S.length()-1;i>=0;i--){
            res+=S[i];
        }
    return res;
    }
0
ashutosh8873 weeks ago
class Solution {   static String conRevstr(String S1, String S2) {       // code here       String ashutosh = S1 + S2;              return new StringBuilder(ashutosh).reverse().toString();       }}
0
jagtapshubham1913 weeks ago
Java Sol.
class Solution {   static String conRevstr(String S1, String S2) {       // code here String str=S1+S2;       // String Concatenated String strrev=""; 
// String reverse for(int i=str.length()-1;i>=0;i--) {     strrev=strrev+str.charAt(i);     } return strrev;   }}
0
mohammadtanveer75404 weeks ago
class Solution {
  public:
    string conRevstr(string s1, string s2) {
        s1=s1+s2;
        for(int i=s1.size()-1;i>=0;i--)
            cout<<s1[i];
        return "";
    }
};
0
sonalyadav452 months ago
class Solution {   static String conRevstr(String S1, String S2) {       String concatStr = S1.concat(S2);       StringBuffer reverseStr = new StringBuffer(concatStr);       return reverseStr.reverse().toString();   }}
0
rajatsilwal992 months ago
class Solution {   static String conRevstr(String S1, String S2) {          StringBuilder str =  new StringBuilder();      str.append(S1);   str.append(S2);      str.reverse();     return str.toString();   }}
0
rohitpandey484Premium2 months ago
Why This Java Code is not Working 
class Solution {   static String conRevstr(String S1, String S2) {      String S3=S1.concat(S2);      StringBuffer s4=new StringBuffer(S3);      S3.reverse();      return S3.toString();         }}
0
amanans12th2 months ago
class Solution {   static String conRevstr(String S1, String S2) {       // code here       String con=S1.concat(S2);       String rev="";       int l=con.length();       for(int i=l-1;i>=0;i--)        {          rev+=con.charAt(i);          }        return rev;   }}
0
paritoshkurane5752 months ago
class Solution {
   static String conRevstr(String S1, String S2) {
       String S3 = S1.concat(S2);
       String r = " ";
    
           for(int i = S3.length()-1; i>=0; i--){
           
               r += S3.charAt(i);
           }
           return r;
       }
   }
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.