Amazon Interview Question for Web Developers


Team: AWS
Country: United States
Interview Type: Phone Interview




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

The interviewer said it was exactly what they were looking for.

function reverse(sentence){
	return sentence.split(" ").reverse().join(" ");
}

- Kevin.Pheasey April 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

// in C#
public string ReverseWords(string s)
{
return string.Join(" ", s.Split(' ').Reverse<string>());
}

- cristiscu April 18, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 4 vote

public class WordReverse {
    
    public static String reverseWords(String startString){
        String endString = "";
        String[] startArray = startString.split(" ");
        for (int i = startArray.length - 1; i >= 0; i--){
            endString += startArray[i];
            if (i != 0){
                endString += " ";
            }
        }
        
        return endString;
    }
    
    public static void main(String[] args){
        String s = "these are words that will be reversed";
        System.out.println(s);
        System.out.println(reverseWords(s));
    }
}

- Frank April 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 4 votes

Remember this is JavaScript, not Java.

- Kevin.Pheasey April 10, 2013 | Flag
Comment hidden because of low score. Click to expand.
1
of 7 votes

Where the hell did you even mention javascript? be more percise next time before downvoting me, asshole.

- Frank April 10, 2013 | Flag
Comment hidden because of low score. Click to expand.
3
of 3 votes

The question is tagged as JavaScript and as Web Developer.

- Kevin.Pheasey April 10, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Kevin.Pheasey

So, now you are with Amazon?

- Murali Mohan August 21, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

var s="these are words that will be reversed";
String.prototype.reverse = function() {
return this.split('').reverse().join('');
}
s.split(' ').map(function(w){return w.reverse()});

- Eugene May 21, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Another way without reverse():

function reverse(sentence) {
    var words = sentence.split(" ");
    while(words.length) {
        console.log(words.pop());
    }
}

reverse("hello world i am a robot");

- stuartmark September 06, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

function reverseWords(sentence){
var strArray = sentence.split(" ");
for(i=0; i<strArray.length; i++){
strArray[i] = strArray[i].split("").reverse().join("");
}
return strArray.join(" ");
}

- Dins November 11, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Here is the answer in Ruby:

require 'pry'

def reverse_sentence(sentence)
sent_arr = sentence.split(' ')
reversed = []
sent_arr.each do |word|
reversed.unshift(word)
end
reversed.join(' ')
end


print reverse_sentence('Hi how are you? Hi how are you? Hi how are you? Hi how are you?')


- Alex M.

- alexmorgan.AM September 22, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

JS solution:

function reverseSentence(str){
	return str.split(" ").reverse().join().replace(/,/g, " ");
}


var someSentence = "Create a function that will reverse the words in a sentence";
var newOrder = reverseSentence(someSentence);
console.log(newOrder);

- arielbarkan July 11, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

function reverse(sentence) {
var words = sentence.split(" ");
var temp="";
var i=1;
while(words.length){
temp = temp+" "+words.shift().split("").reverse().join("");
}
console.log(temp)
}

reverse("hello world i am a robot");

- Santosh January 30, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

function reverse(sentence) {
    var words = sentence.split(" ");
    var temp="";
    var i=1;
    while(words.length){
          temp = temp+" "+words.shift().split("").reverse().join("");
    }
    console.log(temp)
}

reverse("hello world i am a robot");

- Santosh January 30, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

public string Reverse(string str)
{
	if(str.Length == 1)
		return str;
		
	return str[str.Length - 1] + Reverse(str.Substring(0,str.Length - 1));
}

- Anonymous April 21, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

str[str.Length - 1] ???

- aopencv July 09, 2013 | Flag


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