Problem

  • Given a string
  • Write an algorithm to reverse words in it

Example

  • Input: given the string "Hello Koding". Expected output: "Koding Hello"

Approach

  • Split the given string into words array
  • Reverse for-loop the words array to build the result string

Implementation


Complexity

  • Time complexity: O(n)
  • Space complexity: O(n)