Motorola Mobility
Employer Engaged

Interview Question

Software Engineering Intern Interview(Student Candidate) Sunnyvale, CA

Reverse the words in a string, but not the characters. Do

  it in linear time.

Interview Answer

2 Answers


Google it, not hard at all.

Interview Candidate on 2010-02-17

public String reverseWords(String in){
String[] tokens = in.split("");
if(tokens.length <= 1) return in;
StringBuilder sb = new StringBuilder();
for(int i = tokens.length-1; i >= 0; i--)

return sb.toString();

ST on 2012-03-13

Add Answers or Comments

To comment on this, Sign In or Sign Up.