public static String reverseWords(char[] s) {
        if(s == null || s.length == 0){
            return null;
        }
        //step one is to reverse the string
        reverse(s, 0, s.length -1);
        int start = 0;
        int end = 0;
        while(end < s.length && start < s.length) {

            // move to the first character of the word by skipping whitespaces
            while(start < s.length && s[start] == ' '){
                start++;
            }

            end = start;
            while(end+1 < s.length && s[end+1] != ' '){
                end ++;
            }

            // found the word hence reverse it
            reverse(s, start, end);
            start = end+1;
        }

        return new String(s);
    }