Frage im Vorstellungsgespräch bei Amazon

Reverse a string

Antworten zu Vorstellungsgespräch

Anonym

12. Sep. 2018

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

2

Anonym

21. Juli 2018

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

1

Anonym

8. Feb. 2020

How about this: for(int index = 0; index < input.length() ; index++ ) { output.insert(0, input.charAt(index)); }

Anonym

13. Mai 2016

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

Anonym

16. Apr. 2017

// 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 >= 0; i--) { // Add character sb.append(a[i]); } // Print out the string System.out.println(sb);

Anonym

15. Mai 2017

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

Anonym

28. Apr. 2014

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

Anonym

1. Okt. 2018

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

Anonym

4. Mai 2014

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