1) Fixed the solution that uses stack(check for empty string after trim) and split library. 2) Added the space-O(1) solution.