Amazon Interview Question: Reverse a string... | Glassdoor

## Interview Question

Quality Assurance Engineer Interview Seattle, WA

# Reverse a string

0

Using Python :

def reverse(string):
L = []
count = 1
for i in range(0,len(string)):
L.append(string[len(string)-count])
count += 1
L_reverse = ''.join(L)
return L_reverse

Anonymous on Apr 28, 2014
0

public String reverseMe(String string1) {
int length = string1.length();
char[] charArray = new char[length];
int j = 0;
for(int i = length -1 ; i &gt;= 0 ; i--) {
charArray[j++] = string1.charAt(i);

}

String string2 = new String(charArray);
return string2;
}

Vicky D on May 4, 2014
0

String n='he'
for (int i=n.length-1; i--;i&gt;=0){
String n_rev = n.CharAt(i)+n;
}
System.out.println(n_rev);

FNU Madhulika on May 13, 2016
0

// Converted the String into Char array
char[] a = str.toCharArray();
// create a new String
StringBuilder sb = new StringBuilder();
// Started a loop
for (int i = a.length - 1; i &gt;= 0; i--) {
sb.append(a[i]);
}
// Print out the string
System.out.println(sb);

Nitesh on Apr 16, 2017
0

Ruby :

a = "This test is simple".downcase
b = a.chars.to_a
temp = []
len = b.length
for i in 1...len+1
temp.push(b[-i])
end

f = temp.join
print f

Output: elpmis si tset siht

Using Ruby : on May 15, 2017
1

Javascript

const foo = "bar";
const baz = foo.split('').reverse().join('');

:^)

Anonymous on Jul 20, 2018
0

def main():
str=input("Enter a string")
print(str[: : -1])
main()

Ashish on Sep 11, 2018
0

# Python:
def reverse_str(s):
return s[::-1]

Viktor on Oct 1, 2018