Amazon Interview Question for Testing / Quality Assurances


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
2
of 2 vote

A more optimal Java solution...

private static String reverse(String s) {
        char[] letters = s.toCharArray();
        int length = letters.length;
        length--;
        
        char a, b;
        for(int i = 0; i <= (length/2); i++) {
            a = letters[i];
            b = letters[length-i];
            
            letters[i] = b;
            letters[length-i] = a;            
        }
        
        return new String(letters);
    }

- Aham December 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

import java.io.*;
import java.util.*;


class rf{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String str = sc.nextLine();

		//Solution 1.
		int l=str.length();
		String reverse="";
		for(int i=l-1;i>=0;i--)
			reverse= reverse + str.charAt(i);
		System.out.println(reverse);

		//Soultion 2.
/*
		StringBuilder sb= new StringBuilder(str);
		reverse = sb.reverse().toString();
		System.out.println(reverse);
*/

}

}

- neerajlakhotia08 December 27, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

import java.io.*;
import java.util.*;
class ReverseString {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
StringBuilder builder=new StringBuilder(str);
String reversed = builder.reverse().toString();
System.out.println(reversed);
}
}

- mohammed imran December 29, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{{
import java.util.Scanner;
class reverse{
public static void main(String[]args){
Scanner scan=new Scanner(System.in);
System.out.println("Enter A String");
String s=scan.next();
String r="";
for(int i=s.length()-1;i>=0;i--){
r=r+(char)s.charAt(i);
}
System.out.println("Reverse O f a String "+r);
}
}
}}

- lavakumarfire999 December 31, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{{ public static String reverse(String s){

int length = s.length(), last = length - 1 ;
char[] chars = s.toCharArray();

for(int i = 0 ; i < length/2 ; i++)
{
char c = chars[last-i];
chars[last-i] = chars[i];
chars[i] = c;
}

return String.copyValueOf(chars);
} }}

- Tesfay Aregay January 02, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String reverse(String s){
    
        int length = s.length(), last = length - 1 ;
        char[] chars = s.toCharArray();
        
        for(int i = 0 ; i < length/2 ; i++)
        {
            char c = chars[last-i];
            chars[last-i] = chars[i];
            chars[i] = c;
        }
        
        return String.copyValueOf(chars);       
    }

- Tesfay Aregay January 02, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String reverse(String s){
    
        int length = s.length(), last = length - 1 ;
        char[] chars = s.toCharArray();
        
        for(int i = 0 ; i < length/2 ; i++)
        {
            char c = chars[last-i];
            chars[last-i] = chars[i];
            chars[i] = c;
        }
        
        return String.copyValueOf(chars);       
    }

- Tesfay Aregay January 02, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static String reverse(String s){
    
        int length = s.length(), last = length - 1 ;
        char[] chars = s.toCharArray();
        
        for(int i = 0 ; i < length/2 ; i++)
        {
            char c = chars[last-i];
            chars[last-i] = chars[i];
            chars[i] = c;
        }
        
        return String.copyValueOf(chars);       
    }

- TesfayAregay January 02, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Step 1: convert to char array
Step 3 : declare a stack
Step 4: push each char in stack
Step 5: pop each char to form reverse

- Pradip Acharya January 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class reverse_string 
{
	public static void main(String[] args)
	{
		String str= "Hello World";
		String revstring=" ";
		for(int i=str.length()-1;i>=0;i--)
		{
			revstring+=str.charAt(i);
		}
		System.out.println(revstring);
	}

}

- qwerty.social January 22, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class reverseString {
    public static void main (String[] args) {
        String str = new String ("hello World");
        char[] c = str.toCharArray();
        int first = 0;
        int last = str.length() -1;

        while (first < last) {
            char tmp = str.charAt(first);
            c[first] = str.charAt(last);
            c[last]= tmp;
            first++;
            last--;
        }

        System.out.println(new String(c));
    }
}

- ajnavi July 31, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

I write code in c/c++. Here is the implementation in c/C++

#include <iostream>
#include <cstring>
#include <string>
using namespace std;
bool reverseStr (char *input)
{
int maxChars = strlen(input);
char temp;

for (int i=0;i<=maxChars/2-1;++i)
{
temp=input[maxChars-i-1];
input[maxChars-i-1] = input[i];
input[i]=temp;
}
}

int main ()
{
cout << "Entering main "<<endl;
string sinput;
cout << "Enter the sting which you want to get reversed "<<endl;
cin >> sinput;
cout << "The string to be reversed is "<<sinput<<endl;
char *output = new char[sinput.length()+1];
strcpy(output, sinput.c_str());
reverseStr(output);
cout << " The reversed string is ["<<output <<"]"<<endl;

}

- ToAjitkc December 26, 2016 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More