Reverse Words in a String
Given an input string, reverse the string word by word. [#151]
Examples: Input: "the sky is blue" Output: "blue is sky the" Input: " hello world! " Output: "world! hello" Explanation: Your reversed string should not contain leading or trailing spaces. Input: "a good example" Output: "example good a" Explanation: You need to reduce multiple spaces between two words to a single space in the reversed string.
Note:
A word is defined as a sequence of non-space characters.
Input string may contain leading or trailing spaces. However, your reversed string should not contain leading or trailing spaces.
You need to reduce multiple spaces between two words to a single string.
Follow up:
For C programmers, try to solve it in-place in O(1) extra space.
Maximum Product Subarray
Given an integer array nums , find the contiguous subarray within an array (containing at least one number) which has the largest product. [#152]
Examples: Input: [2,3,-2,4] Output: 6 Explanation: [2,3] has the largest product 6. Input: [-2,0,-1] Output: 0 Explanation: The result cannot be 2, because [-2,-1] is not a subarray.