I was asked this question in one of the interviews. I got feedback from the recruiter saying I didn't solve this problem in place. I was wondering why this solution is not in place? What did I miss here?
Input is the character list like ['h','o','w',' ','a','r','e',' ','y','o','u','?']. The output should be a string like ?you are how.
charArr = ['h','o','w',' ','a','r','e',' ','y','o','u','?']
#output = ?you are how
class Solution():
def reverseStr(self,charArr):
charArr = ''.join(charArr).split()[::-1]
for i in range(len(charArr)):
if not charArr[i][-1].isalnum():
charArr[i] = charArr[i][-1] + charArr[i][:-1]
print ' '.join(charArr)
s1 = Solution()
s1.reverseStr(charArr)