View All num of num See all Photos Microsoft This employer has taken extra steps to respond to reviews and provide job seekers with accurate company information, photos, and reviews. Interested for your company?Learn More. www.microsoft.com www.microsoft.com Work in HR? Unlock Free Profile Overview Reviews Salaries Interviews Jobs Photos Benefits 8.8k Reviews 31k Salaries 3.8k Interviews Follow Add Review or Salary Follow Add Review or Salary Microsoft 8788 Interview Question Software Developer I Interview(Student Candidate) Redmond, WA Microsoft Write an algorithm to reverse a string. Apply that algorithm to reverse a sentence. Tags: algorithm See more , See less 8 Answer Add Tags Flag as Inappropriate Thank you! Your feedback has been sent to the team and we'll look into it. Oops! We're sorry but your feedback didn't make it to the team. Your input is valuable to us — would you mind trying again? Send Answer Interview Answer 1 Answer ▲ 0 ▼ Reversing a string is easy: Index at the start moving toward the end, index at the end moving to the front. Swap the letters at each index and increment / decrement the indices respectively. O(n)My first attempt at reversing the sentence, I reversed the entire sentence string, then split the sentence into words and reversed each word. O(n * w). The best way is to split on white spaces first and make the previous algorithm generic so that you aren't just constrained to swapping letters. Then swap words of a sentence in the same way that you would swap letters of a word. O(w) Interview Candidate on Sep 26, 2012 Flag as Inappropriate Thank you! Your feedback has been sent to the team and we'll look into it. Oops! We're sorry but your feedback didn't make it to the team. Your input is valuable to us — would you mind trying again? Send Add Answers or Comments To comment on this, Sign In or Sign Up.