Grubhub Interview Question: Write a function to reverse a... |

Interview Question

Software Engineer Interview

Write a function to reverse all the words in a string

  separated by spaces. There will be k spaces, and k + 1 words.

Interview Answer

3 Answers


var rev = function ( x ){
    return x.split(" ").reverse().join(" ");

Anonymous on 2 Jun 2015

def reverse_sentence(words):
    return ' '.join([word for word in words.split()[::-1]])

In Python on 2 Sep 2016

If you're looking for interview questions, try Rooftop Slushie - it's the easiest way to get questions and answers from current employees at Google, Facebook, Grubhub, and +50,000 companies.

Anonymous on 11 Jul 2019

Add Answers or Comments

To comment on this, Sign In or Sign Up.