Amazon Interview Question for Quality Assurance Engineers


Country: India
Interview Type: In-Person




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

import java.util.*;
public class Main{
	public static void main(String[] args){
		String input = "Run interactive";
		Integer interval = 4;

		Integer start = 0;
		String revInput = "";
		while((start + interval) < input.length()){
			revInput = reverseMe(input, start, start + interval, revInput);
			start = start + interval;
		}
		if(revInput.length() < input.length()){
			revInput = reverseMe(input, start, input.length(), revInput);
		}
		System.out.println(revInput);
	}
	public static String reverseMe(String input, Integer start, Integer end, String addTo){
		StringBuilder sb = new StringBuilder(input.substring(start, end));
		return (addTo + sb.reverse());	
	}
}

- Rajiv Bhati February 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
public class Main{
	public static void main(String[] args){
		String input = "Run interactive";
		Integer interval = 4;

		Integer start = 0;
		String revInput = "";
		while((start + interval) < input.length()){
			revInput = reverseMe(input, start, start + interval, revInput);
			start = start + interval;
		}
		if(revInput.length() < input.length()){
			revInput = reverseMe(input, start, input.length(), revInput);
		}
		System.out.println(revInput);
	}
	public static String reverseMe(String input, Integer start, Integer end, String addTo){
		StringBuilder sb = new StringBuilder(input.substring(start, end));
		return (addTo + sb.reverse());	
	}
}

- Rajiv Bhati February 06, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/**
 * Created by rajive.pai on 2/22/2017.
 */
public class ReverseInterval {


    public static String reverseAString(String s){


        String reverse = "";
        for(int i = s.length()-1; i>=0 ; i--){

            reverse = reverse + s.charAt(i);

        }

        return reverse;

    }

    public static String revInteval(String s, int interval){

        int j =0;
        String reverse = "";

        for(int i = (interval-1); i<s.length(); i+=interval){
            String toReverse = s.substring(j,i+1);
            reverse = reverse + "-" + reverseAString(toReverse);
            j = i+1;

        }
        reverse += s.substring(j);
        return reverse;
    }


    public static void main(String args[]){

        System.out.println("Reverse with interval 2 for \"Pracbox Prime\" is " + revInteval("Pracbox Primere", 4));

    }

}

- rajivmailing February 22, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

/**
*
*/
package com.test.abhijeet.java6.examples;

/**
* @author Abhijeet Mohanty
*
*/
public class ReverseString {

private String name = "Abhijeet Mohanty";
private StringBuffer tempStr1 = new StringBuffer();
private StringBuffer tempStr2 = new StringBuffer();

/**
* @param args
*/
public static void main(String[] args) {
new ReverseString().reverse();
}

private void reverse() {
boolean isNextStringBlank = false;
char[] namechr = name.toCharArray();
for (int i = 0; i < namechr.length; i++) {
if (!isNextStringBlank ) {
tempStr1.append(namechr[i] + "");
}
if (namechr[i] == ' ') {
isNextStringBlank = true;
}
if (isNextStringBlank) {
tempStr2.append(namechr[i] + "");
}
}
String firstReverse = reverse(tempStr1.toString());
String secondReverse = reverse(tempStr2.toString());
System.out.println(firstReverse+""+secondReverse);
}

private String reverse(String string) {
StringBuffer sb = new StringBuffer();
char[] chararr = string.toCharArray();
for(int i = chararr.length-1;i>= 0;i--){
sb.append(chararr[i]);
}
return sb.toString();
}
}

- Abhijeet Mohanty February 25, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class reverseInterval {

public static String reverseString(String s){
String reverse = "";
for(int i = s.length() - 1; i>=0 ; i--){
reverse = reverse + s.charAt(i);
}
return reverse;
}

public static String reverseInteval(String s, int interval){
if ( s == null ) {
return null;
}
String toReverse = s.substring(0,interval);
String reverse = reverseString(toReverse);
for(int i =interval; i<s.length(); i++){
Character origString = s.charAt(i);
reverse = reverse + origString;
}
return reverse;
}

public static void main(String args[]){

System.out.println("Reverse interval output is: " + reverseInteval("rev substring", 4));

}


}

- manasa0930 February 28, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.*;
class StringReversal
{

public static void main(String args[])
{
StringBuffer sb=new StringBuffer("Hello Good Morning");
StringBuffer sb1=new StringBuffer();//to store reverse string
int interval=3;
int length=sb.length();
for(int i=0;i<length;i=i+interval)
{
String s1=sb.substring(i,i+interval);
StringBuffer rs1=new StringBuffer(s1);
rs1.reverse();
sb1.append(rs1);
}
System.out.println("Reverse of sb is"+ sb1);
}
}

- Deepthi March 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Just curious, Cant we use in built functions instead of using complex logic?

- Deepthi March 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static string ReverseString(string str)
{
char[] chars = str.ToCharArray();
for (int i = 0, j = str.Length - 1; i < j; i++, j--)
{
chars[i] = str[j];
chars[j] = str[i];
}
return new string(chars);
}

- Arif May 13, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static string ReverseString3(string str)
        {
            char[] chars = str.ToCharArray();
            //We can either user ToCharArray() to create chars array as above OR simply char[str.Length] as below
            //char[] chars = new char[str.Length]; 
            for (int i = 0, j = str.Length - 1; i < j; i++, j--)
            {
                chars[i] = str[j];
                chars[j] = str[i];
            }
            return new string(chars);
        }

- Arif May 13, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.BufferedReader;
import java.io.InputStreamReader;



public class ReverseStringIntervals {
public static void main(String[] args) {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder reverseString = new StringBuilder();
try {

System.out.println("Enter interval size to reverse a string");
Integer interval = Integer.parseInt(br.readLine());
System.out.println("Enter String to Reverse");
String string = br.readLine();
int count = 1;
int index = 1;
for (int index1 = 1; index <= string.length() && interval * count <= string.length(); index++, index1++) {
if (interval <= 0)
break;
else if (index1 <= interval) {
reverseString.append(string.charAt(interval * count - index1));
continue;
} else {
index1 = 0;
index--;
}
count++;
}
index--;
while (index < string.length()) {
reverseString.append(string.charAt(index));
index++;
}

System.out.println("Reverse String is:" + reverseString);
}
catch (Exception e) {
}
}
}

- Swamy May 13, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.Stack;

/**
 * Created by USABOS133592LADM on 5/11/2017.
 */
public class ReverseStringIntervals {
    public static void main(String[] args) {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder reverseString = new StringBuilder();
        try {

            System.out.println("Enter interval size to reverse a string");
            Integer interval = Integer.parseInt(br.readLine());
            System.out.println("Enter String to Reverse");
            String string = br.readLine();
            int count = 1;
            int index = 1;
            for (int index1 = 1; index <= string.length() && interval * count <= string.length(); index++, index1++) {
                if (interval <= 0)
                    break;
                else if (index1 <= interval) {
                    reverseString.append(string.charAt(interval * count - index1));
                    continue;
                } else {
                    index1 = 0;
                    index--;
                }
                count++;
            }
            index--;
            while (index < string.length()) {
                reverseString.append(string.charAt(index));
                index++;
            }

            System.out.println("Reverse String is:" + reverseString);
        } 
        catch (Exception e) {
        }
    }
}

- Sw May 13, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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

String word = sc.nextLine(), reverse="";

int n =sc.nextInt();

int len = word.length();

for(int i=len-1; i>=n; i--)
{
reverse = reverse + word.charAt(i);
}

System.out.println(reverse);
sc.close();
}

- Charankumar. H June 08, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

string myString = "Coding in C#123";
int interval = 2;
string reverseInt = "";
int i4;
string subStr;
string strDup = myString;
for (i4 = 0; i4 < myString.Length; i4 += interval)
{
if (myString.Length >= interval)
{
subStr = myString.Substring(i4, interval);
}
else
{
subStr = myString.Substring(i4, myString.Length);
}
for (int i5 = subStr.Length - 1; i5 >= 0; i5--)
{
reverseInt += subStr[i5].ToString();
}

myString = myString.Remove(0, subStr.Length);
i4 = -interval;
}
Console.WriteLine("Input string: " + strDup + ", Output string after reversing at interval: " + interval + ", " + reverseInt);
Console.ReadKey();

- Here's my take on the problem in C# October 22, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

string myString = "Coding in C#123";
            int interval = 2;
            string reverseInt = "";
            int i4;
            string subStr;
            string strDup = myString;
            for (i4 = 0; i4 < myString.Length; i4 += interval)
            {
                if (myString.Length >= interval)
                {
                   subStr = myString.Substring(i4, interval);
                }
                else
                {
                    subStr = myString.Substring(i4, myString.Length);
                }
                for (int i5 = subStr.Length - 1; i5 >= 0; i5--)
                {
                    reverseInt += subStr[i5].ToString();
                }
                
                myString = myString.Remove(0, subStr.Length);
                i4 = -interval;
            }
            Console.WriteLine("Input string: " + strDup + ", Output string after reversing at interval: " + interval + ", " + reverseInt);
            Console.ReadKey();

- Anonymous October 22, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is my take in C#:

string myString = "Coding in C#123";
            int interval = 2;
            string reverseInt = "";
            string subStr;
            string strDup = myString;
            for (int i4 = 0; i4 < myString.Length; i4 += interval)
            {
                if (myString.Length >= interval)
                {
                   subStr = myString.Substring(i4, interval);
                }
                else
                {
                    subStr = myString.Substring(i4, myString.Length);
                }
                for (int i5 = subStr.Length - 1; i5 >= 0; i5--)
                {
                    reverseInt += subStr[i5].ToString();
                }
                
                myString = myString.Remove(0, subStr.Length);
                i4 = -interval;
            }
            Console.WriteLine("Input string: " + strDup + ", Output string after reversing at interval: " + interval + ", " + reverseInt);
            Console.ReadKey();

- vg0453 October 22, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

My Python code:

def rev_string(s):
    str = ''
    ans = ''
    for i in s:
        if i != ' ':
            str = str + i
        else:
            ans = str + ' ' + ans
            str = ''
    ans = str + ' ' + ans
    print ans

str= "Welcome to the World"
rev_string(str)

- Gopinath November 03, 2017 | 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