In this Kata, we are going to reverse a string while maintaining the spaces (if any) in their original place.

For example:
```
solve("our code") = "edo cruo"
-- Normal reversal without spaces is "edocruo". 
-- However, there is a space at index 3, so the string becomes "edo cruo"

solve("your code rocks") = "skco redo cruoy". 
solve("codewars") = "srawedoc"
```
More examples in the test cases. All input will be lower case letters and in some cases spaces.

Good luck!

Please also try:

[Simple time difference](https://www.codewars.com/kata/5b76a34ff71e5de9db0000f2)

[Simple remove duplicates](https://www.codewars.com/kata/5ba38ba180824a86850000f7)

Difficulty: EASY

Starter code:
def solve(s):
	

Solutions:
def solve(s):
	it = reversed(s.replace(' ', ''))
	return ''.join((c if c == ' ' else next(it) for c in s))


def solve(s):
	space_index = [i for i in range(len(s)) if s[i] == ' ']
	s = ''.join(s.split())
	s = s[::-1]
	for i in space_index:
		s = s[:i] + ' ' + s[i:]
	return s


def solve(s):
	rev = list(s.replace(' ', '')[::-1])
	for (index, item) in enumerate(s):
		if item == ' ':
			rev.insert(index, item)
	return ''.join(rev)


def solve(s):
	r = list(s.replace(' ', ''))
	return ''.join((i if i == ' ' else r.pop() for i in s))


def solve(s):
	it = iter(s.replace(' ', '')[::-1])
	return ''.join((' ' if c == ' ' else next(it) for c in s))


def solve(s):
	r = [a for a in s if a != ' ']
	return ''.join((a if a == ' ' else r.pop() for a in s))


solve = lambda s: (lambda j=reversed(s.replace(' ', '')): ''.join((e if e == ' ' else next(j) for e in s)))()


def solve(s):
	slist = []
	for i in s:
		slist.append(i)
	c = 0
	res = []
	for i in slist:
		if slist[c] == ' ':
			res.append(c)
			slist.remove(slist[c])
		c += 1
	s_rev = slist[::-1]
	c = 0
	for i in s_rev:
		if c + 1 in res:
			s_rev[c] = s_rev[c] + ' '
		c += 1
	return ''.join((i for i in s_rev))


def solve(s):
	if s.count(' ') >= 1:
		positions = [i for i in range(len(s)) if s[i] == ' ']
		l = [i for i in s if i != ' '][::-1]
		for i in positions:
			l.insert(i, ' ')
		return ''.join(l)
	else:
		return s[::-1]


def solve(s):
	tempr = list(s)
	ts = tempr.count(' ')
	for i in range(ts):
		tempr.remove(' ')
	tempr = tempr[::-1]
	s = list(s)
	it = 0
	iw = 0
	while iw != len(s):
		if s[iw] == ' ':
			iw += 1
		else:
			s[iw] = tempr[it]
			it += 1
			iw += 1
	return ''.join(s)


def solve(s):
	char = s.replace(' ', '')[::-1]
	list = s.split(' ')
	i = 0
	for x in list:
		list[i] = char[:len(x)]
		char = char[len(x):]
		i += 1
	return ' '.join(list)


def solve(s):
	spaceIndex = []
	result = []
	index = 0
	for i in s:
		if i != ' ':
			result.insert(1, i)
		else:
			spaceIndex.append(index)
		index += 1
	result.append(result[0])
	result.pop(0)
	for j in range(0, len(spaceIndex)):
		result.insert(spaceIndex[j], ' ')
	return ''.join(result)


def solve(s):
	if len(s) < 2:
		return s
	if s[0] == ' ':
		return ' ' + solve(s[1:])
	if s[-1] == ' ':
		return solve(s[:-1]) + ' '
	return s[-1] + solve(s[1:-1]) + s[0]


def solve(s):
	z = reversed(s.replace(' ', ''))
	return ''.join((' ' if i == ' ' else next(z) for i in s))


def solve(s):
	ans = list(s.replace(' ', '')[::-1])
	for i in [i for (i, item) in enumerate(s) if item == ' ']:
		ans.insert(i, ' ')
	return ''.join(ans)


def solve(s):
	ys = iter((y for y in reversed(s) if y != ' '))
	return ''.join((next(ys) if x != ' ' else x for x in s))


solve = lambda s: (lambda ns=reversed(s.replace(' ', '')): ''.join((e == ' ' and ' ' or next(ns) for e in s)))()


def solve(s):
	s_list = s.split(' ')
	s_nospace = ''
	for i in s_list:
		s_nospace += i
	s_nospace_reverse = ''
	for i in range(1, len(s_nospace) + 1):
		s_nospace_reverse += s_nospace[-i]
	final_s = ''
	space_index = []
	for i in range(0, len(s)):
		if s[i] == ' ':
			space_index.append(i)
	sdvig = 0
	for i in range(0, len(s_nospace)):
		if i + sdvig in space_index:
			final_s += ' '
			sdvig += 1
		if i < len(s_nospace):
			final_s += s_nospace_reverse[i]
	if s[-1] == ' ':
		final_s += ' '
	return final_s


def solve(s):
	lst_s = list(s)
	(i, j) = (0, len(s) - 1)
	while j > i:
		if lst_s[i] == ' ' or lst_s[j] == ' ':
			if lst_s[i] == ' ':
				i += 1
			if lst_s[j] == ' ':
				j -= 1
			continue
		else:
			(lst_s[i], lst_s[j]) = (lst_s[j], lst_s[i])
			i += 1
			j -= 1
	return ''.join(lst_s)


def solve(s):
	reversed = list(''.join(s.split())[::-1])
	for i in range(len(s)):
		if s[i] == ' ':
			reversed.insert(i, ' ')
	return ''.join(reversed)


import re

def solve(s):
	space_index = [m.start() for m in re.finditer(' ', s)]
	reverse = s.replace(' ', '')[::-1]
	list_reverse = list(reverse)
	for index in space_index:
		list_reverse.insert(index, ' ')
	return ''.join(list_reverse)


import re

def solve(s):
	swap = reversed([m.start() for m in re.finditer('[^ ]', s)])
	return ''.join((s[next(swap)] if c != ' ' else c for c in s))


import re

def solve(s):
	result = list(s)
	indices = [m.span()[0] for m in re.finditer('[^ ]', s)]
	for (a, b) in zip(indices, indices[::-1]):
		result[a] = s[b]
	return ''.join(result)


def solve(s):
	string = s
	string = string.split()
	string = ''.join(string)
	string = string[::-1]
	space_list = []
	for (i, char) in enumerate(s):
		if char == ' ':
			space_list.append(i)
	for space in space_list:
		first_chunk = string[0:space]
		first_chunk += ' '
		string = first_chunk + string[space:]
	return string


def solve(s):
	indexes = []
	for i in range(len(s)):
		if s[i] == ' ':
			indexes.append(i)
	lst = s.split(' ')
	result = []
	for i in range(len(lst)):
		result.append(lst[i][::-1])
	result.reverse()
	t = ''.join(result)
	t = list(t)
	for i in range(len(indexes)):
		t.insert(indexes[i], ' ')
	return ''.join(t)


def solve(s):
	print(s)
	l = [c for c in s if c != ' ']
	l.reverse()
	for (i, c) in enumerate(s):
		if c == ' ':
			l.insert(i, c)
	return ''.join(l)


def solve(c):
	k = ''.join(reversed(c))
	h = k.replace(' ', '')
	s = [i for i in range(len(c)) if ' ' == c[i]]
	h = list(h)
	for i in range(len(c)):
		if i in s:
			h.insert(i, ' ')
	return ''.join(h)


def solve(s):
	s_ = list(''.join(s.split())[::-1])
	for (i, l) in enumerate(s):
		if l == ' ':
			s_.insert(i, l)
	return ''.join(s_)


def solve(s):
	new_s = [x if x.isalpha() else '' for x in s[::-1]]
	for char in new_s:
		if char == '':
			new_s.remove(char)
	for i in range(len(s)):
		if s[i] == ' ':
			new_s.insert(i, s[i])
	return ''.join(new_s)


def solve(s):
	s = s.split(' ')
	temp = []
	result = []
	for l in s:
		temp.append(len(l))
	s = ''.join(s)
	s = s[::-1]
	for x in temp:
		add = s[:x]
		s = s[x:]
		result.append(add)
	a = ''
	for i in result:
		a += i + ' '
	a = a[:-1]
	return a


def solve(s):
	sr = s[::-1]
	sr = sr.replace(' ', '')
	x = [pos for (pos, char) in enumerate(s) if char == ' ']
	for i in range(0, len(x)):
		sr = sr[:x[i]] + ' ' + sr[x[i]:]
	return sr


def solve(s):
	rev_s = [*s.replace(' ', '')]
	return ''.join([rev_s.pop() if c != ' ' else ' ' for c in s])


def solve(s):
	inds = [i for (i, c) in enumerate(s) if c == ' ']
	res = s.replace(' ', '')[::-1]
	for i in inds:
		res = res[:i] + ' ' + res[i:]
	return res


def solve(s):
	x = []
	for k in list(range(0, len(s))):
		if s[k] == ' ':
			x.append(k)
	y = s.split()
	y = y[::-1]
	z = []
	for k in y:
		z.append(k[::-1])
	y = []
	for k in z:
		y += list(k)
	for k in x:
		y.insert(k, ' ')
	j = ''
	for k in y:
		j += k
	return j


def solve(s):
	new = list(s.replace(' ', '')[::-1])
	[new.insert(i, ' ') for (i, j) in enumerate(s) if j == ' ']
	return ''.join(new)


def solve(s):
	u = []
	reversed_list = list(s[::-1].replace(' ', ''))
	[u.append(reversed_list.pop(0) if c.isalpha() else ' ') for c in s]
	return ''.join(u)


def solve(s):
	s_rev = s[::-1].replace(' ', '')
	for i in range(len(s)):
		if s[i] == ' ':
			s_rev = s_rev[:i] + ' ' + s_rev[i:]
	return s_rev


def solve(s):
	sl = [i for (i, e) in enumerate(s) if e == ' ']
	ans = list(''.join(s[::-1].split(' ')))
	for i in sl:
		ans.insert(i, ' ')
	return ''.join(ans)


def solve(s):
	d = ''
	for i in range(len(s)):
		el = s[i]
		if el.isalpha():
			d = el + d
	for i in range(len(s)):
		el = s[i]
		if el == ' ':
			d = d[:i] + el + d[i:]
	return d


def solve(s):
	y = s.replace(' ', '')
	backwards = y[::-1]
	c = 0
	d = 0
	solution = ''
	for i in range(0, len(s)):
		if s[i] == ' ':
			solution += ' '
			c = c + 1
		else:
			solution += backwards[i - c]
	return solution


def solve(s):
	sa = s.replace(' ', '')
	print(sa)
	ml = list(sa)[::-1]
	print(ml, 'kurw')
	y = 0
	for x in range(len(s)):
		if s[x] == ' ':
			print(s[x], 'coo')
			ml.insert(x + y, s[x])
	print(s)
	print(s[::-1])
	print(ml)
	return ''.join(ml)


def solve(s):
	spaceindex = []
	for i in range(0, len(s)):
		if s[i] == ' ':
			spaceindex.append(i)
	s = s.replace(' ', '')[::-1]
	sil = []
	for char in s:
		sil.append(char)
	for num in spaceindex:
		sil.insert(num, ' ')
	return ''.join(sil)


def solve(s):
	st = ''
	a = 0
	arr = []
	for i in s[::-1]:
		if i != ' ':
			st += i
	for j in s:
		if j != ' ':
			a += 1
		elif j == ' ':
			arr.append(a)
			a += 1
	for k in arr:
		st += ' '
		st = st[0:k] + ' ' + st[k:-1]
	return st


def solve(s):
	lst = [i for i in s if i != ' ']
	return ''.join((' ' if i == ' ' else lst.pop() for i in s))


def solve(s):
	y = [i for i in s[::-1] if not i.isspace()]
	for (i, x) in enumerate(s):
		if x == ' ':
			y.insert(i, ' ')
	return ''.join(y)


def solve(s):
	f = [i for i in range(len(s)) if s[i] == ' ']
	s = s.replace(' ', '')[::-1]
	g = ''
	for i in range(len(s)):
		if i in f:
			g += ' ' + s[i]
			f = list(map(lambda x: x - 1, f[1:]))
		else:
			g += s[i]
	return g + (' ' if f else '')


def find(str, ch):
	for (i, ltr) in enumerate(str):
		if ltr == ch:
			yield i

def solve(s):
	new_s = s[::-1].replace(' ', '')
	for idx in list(find(s, ' ')):
		new_s = new_s[:idx] + ' ' + new_s[idx:]
	return new_s


def insert_space(s, res):
	res = list(res)
	for i in range(len(s)):
		if s[i] == ' ':
			res.insert(i, ' ')
	return ''.join(res)

def solve(s):
	temp = s.translate({ord(' '): None})
	res = temp[::-1]
	return insert_space(s, res)


import re

def solve(s):
	iter = re.finditer(' ', s)
	spaces = [x.start(0) for x in iter]
	s_rev = list(s[::-1].replace(' ', ''))
	for i in spaces:
		s_rev.insert(i, ' ')
	return ''.join(s_rev)


def solve(s):
	spc_idx = []
	rs = ''
	for (i, c) in enumerate(s):
		if c == ' ':
			spc_idx.append(i)
		else:
			rs = c + rs
	for i in spc_idx:
		rs = rs[:i] + ' ' + rs[i:]
	return rs


def solve(s):
	spaces = []
	for i in range(len(s)):
		if s[i] == ' ':
			spaces.append(i)
	s = s.replace(' ', '')[::-1]
	while len(spaces) > 0:
		i = spaces.pop(0)
		s = s[:i] + ' ' + s[i:]
	return s


def solve(s):
	(rev, s) = (s[::-1].replace(' ', ''), list(s))
	for i in range(len(s)):
		if s[i] != ' ':
			(s[i], rev) = (rev[0], rev[1:])
	return ''.join(s)


def solve(s):
	L = [i for (i, letter) in enumerate(s) if letter == ' ']
	print(L)
	l_s = list(''.join(s.split()))
	reversed = l_s[::-1]
	for number in L:
		reversed.insert(number, ' ')
	return ''.join(reversed)


def solve(s):
	count = 0
	l = []
	l1 = []
	l1 = list(s)
	l1.reverse()
	for i in s:
		count += 1
		if i == ' ':
			l1.remove(' ')
			l.append(count - 1)
	for j in l:
		l1.insert(j, ' ')
	l1 = ''.join(l1)
	return l1


def solve(s):
	spaces = [i for (i, letter) in enumerate(s) if letter == ' ']
	s = list(s)
	for i in range(len(spaces) - 1, -1, -1):
		s.pop(spaces[i])
	srev = s[::-1]
	for i in range(0, len(spaces)):
		srev.insert(spaces[i], ' ')
	final = ''
	for z in srev:
		final = final + z
	return final


def solve(s):
	rev_s = ''.join(s.split())[::-1]
	res = []
	n = 0
	for i in [len(w) for w in s.split(' ')]:
		if i == 0:
			res.append('')
		else:
			res.append(rev_s[n:n + i])
		n += i
	return ' '.join(res)


def solve(word):
	reverse = ''
	reverse_nospace = []
	for char in range(len(word) - 1, -1, -1):
		reverse += word[char]
	for i in reverse:
		reverse_nospace.append(i)
	for i2 in reverse_nospace:
		if i2 == ' ':
			reverse_nospace.remove(i2)
	char_list = []
	index = []
	for char in word:
		char_list.append(char)
	for (idx, space) in enumerate(char_list):
		if space == ' ':
			index.append(idx)
	final_string = ''
	for position in index:
		reverse_nospace.insert(position, ' ')
	final_string = ''.join(reverse_nospace)
	return final_string


def solve(s):
	space_indexes = [i for (i, c) in enumerate(s) if c == ' ']
	no_spaces_reversed = list(reversed([c for c in s if c != ' ']))
	for index in space_indexes:
		no_spaces_reversed.insert(index, ' ')
	return ''.join(no_spaces_reversed)


def solve(s):
	space = []
	count = 0
	res = ''
	for c in s:
		count += 1
		if c.isalnum() == True:
			res = c + res
		elif c == ' ':
			space.append(count)
	for num in space:
		res = res[:num - 1] + ' ' + res[num - 1:]
	return res


def solve(s):
	slist = list(s)
	revlist = [slist.pop() for _ in range(len(s))]
	revlist[:] = [x for x in revlist if x != ' ']
	slist = list(s)
	for i in range(len(slist)):
		if slist[i] == ' ':
			revlist.insert(i, ' ')
	rev = ''.join(revlist)
	return rev


def solve(s):
	res = []
	spaces = []
	cnt = 0
	for c in s:
		cnt += 1
		if c != ' ':
			res.insert(0, c)
		else:
			spaces.append(cnt)
	for pos in spaces:
		res.insert(pos - 1, ' ')
	return ''.join(res)


def solve(s):
	spaces = [i for (i, c) in enumerate(s) if c == ' ']
	string = list(s.replace(' ', '')[::-1])
	for space in spaces:
		string.insert(space, ' ')
	return ''.join(string)


def solve(s):
	reversed = s[::-1]
	reversed = ''.join(reversed.split(' '))
	spaces = []
	for i in range(len(s)):
		if s[i] == ' ':
			spaces.append(i)
	result = ''
	spacesCount = 0
	for i in range(len(s)):
		if i in spaces:
			result += ' '
			spacesCount += 1
		else:
			result += reversed[i - spacesCount]
	return result


def solve(s):
	indexes = []
	for (n, i) in enumerate(s):
		if i == ' ':
			indexes.append(n)
	res = ''.join(s.split())[::-1]
	for ind in indexes:
		res = res[:ind] + ' ' + res[ind:]
	return res


def solve(s):
	words = s.split()
	cure = ''.join(words)[::-1]
	r = 0
	krum = []
	for i in words:
		krum.append(cure[r:r + len(i)])
		r = r + len(i)
	return ' '.join(krum) if s[len(s) - 1] != ' ' else ' '.join(krum) + ' '


def solve(s):
	spaces = []
	reversed = s
	for index in range(len(reversed)):
		if reversed[index] == ' ':
			spaces.append(index)
	print(spaces)
	reversed = reversed.replace(' ', '')
	reversed = reversed[::-1]
	for space in spaces:
		print(reversed)
		reversed = f'{reversed[:space]} {reversed[space:]}'
	return reversed


def solve(s):
	x = s.split(' ')
	r = []
	for i in x:
		rt = [''] * len(i)
		r.extend(rt)
		r.extend([' '])
	r = r[:len(r) - 1]
	counter = 0
	for i in reversed(x):
		for j in reversed(i):
			if r[counter] == '':
				r[counter] = j
			else:
				r[counter + 1] = j
				counter += 1
			counter += 1
	return ''.join(r)


def solve(s):
	m = s.replace(' ', '')
	r = ''
	i = -1
	for c in s:
		if c != ' ':
			r += m[i]
			i -= 1
		else:
			r += ' '
	return r


def solve(s):
	l = []
	b = []
	for (i, j) in enumerate(list(s)):
		if j.isspace() == True:
			b.append(i)
		else:
			l.insert(0, j)
	for k in b:
		l.insert(k, ' ')
	return ''.join(l)


def solve(s):
	lst = [i for i in s[::-1] if i != ' ']
	for i in range(len(s)):
		if s[i] == ' ':
			lst.insert(i, ' ')
	return ''.join(lst)


import re

def solve(s):
	ws_indices = [match.span()[0] for match in re.finditer(' ', s)]
	rev_s = list(s[::-1].replace(' ', ''))
	for idx in ws_indices:
		rev_s.insert(idx, ' ')
	return ''.join(rev_s)


def solve(s):
	pos = []
	for i in range(len(s)):
		pos.append('')
		if s[i] == ' ':
			pos[i] = ' '
	j = len(s) - 1
	i = 0
	while i < len(s):
		if pos[i] == ' ':
			if s[j] == ' ':
				j = j - 1
				i = i + 1
			else:
				i = i + 1
		elif s[j] != ' ':
			pos[i] = s[j]
			j = j - 1
			i = i + 1
		else:
			j = j - 1
	return ''.join(pos)


def solve(s):
	letters = [l for l in s]
	spaces = [idx for (idx, space) in enumerate(s) if space == ' ']
	reverse_letters = []
	for (i, j) in enumerate(letters):
		reverse_letters.append(letters[-1 - i])
	reverse_letters = [l for l in reverse_letters if l != ' ']
	for (idx, j) in enumerate(spaces):
		reverse_letters.insert(j, ' ')
	return ''.join(reverse_letters)


import re

def solve(s):
	rev = []
	for i in reversed(s):
		if i != ' ':
			rev.append(i)
	spaces = re.compile(' ')
	for m in spaces.finditer(s):
		rev.insert(m.start(), ' ')
	return ''.join(rev)


def solve(s):
	spaces = []
	word = []
	for i in range(len(s)):
		if s[i] == ' ':
			spaces.append(i)
		else:
			word.append(s[i])
	word = word[::-1]
	for i in spaces:
		word.insert(i, ' ')
	var = ''
	return var.join(word)


def solve(s):
	sol = []
	l = []
	for i in range(len(s)):
		if s[i] == ' ':
			l.append(i)
		else:
			sol.append(s[i])
	sol.reverse()
	for i in range(len(l)):
		sol.insert(l[i], ' ')
	return ''.join(sol)


def solve(x):
	w = x.replace(' ', '')
	new_string = ''
	for i in range(1, len(w) + 1):
		new_string += w[-i]
	new_list = [f for f in x]
	start_at = 0
	spaces = []
	for val in new_list:
		if val == ' ':
			spaces.append(new_list.index(val, start_at))
			start_at = new_list.index(val, start_at) + 1
	for i in spaces:
		new_string = new_string[:i] + ' ' + new_string[i:]
	return new_string


def solve(s):
	rev = s[::-1]
	rev2 = ''
	f = ''
	for i in rev:
		if i == ' ':
			continue
		rev2 += i
	j = 0
	for i in s:
		if i == ' ':
			f += ' '
			continue
		f += rev2[j]
		j += 1
	return f
print(solve('i love codewars'))


def solve(s):
	no_space = list(s.replace(' ', '')[::-1])
	for i in [pos for (pos, char) in enumerate(s) if char == ' ']:
		no_space.insert(i, ' ')
	return ''.join(no_space)


def solve(s):
	s = list(s)
	indices = [index for (index, element) in enumerate(s) if element == ' ']
	s = ''.join(s).split()
	s = ''.join(s)
	s = list(s[::-1])
	for i in range(0, 299):
		for j in indices:
			if i == j:
				s.insert(j, ' ')
	return ''.join(s)


def solve(s):
	revs = s[::-1]
	revs = ''.join(revs.split())
	output = ''
	count = 0
	for letter in s:
		if letter != ' ':
			output = output + revs[count]
			count += 1
		else:
			output = output + ' '
	return output


def solve(s):
	wordSizes = [len(x) for x in s.split()]
	reversedS = s.replace(' ', '')[::-1]
	o = []
	for x in wordSizes:
		o.append(reversedS[:x])
		reversedS = reversedS[x:]
	return ' '.join(o) if s[-1] is not ' ' else ' '.join(o) + ' '


def solve(s):
	without = [c for c in s if c != ' ']
	spaces = [i for (i, e) in enumerate(s) if e == ' ']
	rev = without[::-1]
	result = []
	j = 0
	for i in range(len(s)):
		if i in spaces:
			result.append(' ')
		else:
			result.append(rev[j])
			j += 1
	return ''.join(result)


def solve(s):
	index_list = [i for i in range(len(s)) if s.startswith(' ', i)]
	s = s.replace(' ', '')
	reversed_string = [s[-x] for x in range(1, len(s) + 1, 1)]
	for value in index_list:
		reversed_string.insert(value, ' ')
	return ''.join(reversed_string)


def solve(s):
	spaces = [i for i in range(len(s)) if s[i] == ' ']
	letters = ''.join((x for x in s if x != ' '))[::-1]
	output = ''
	j = 0
	for i in range(len(s)):
		if i in spaces:
			output += ' '
		else:
			output += letters[j]
			j += 1
	return output


def solve(forward_string):
	reverse_string = list(forward_string[::-1].replace(' ', ''))
	for (index, elem) in enumerate(forward_string):
		if elem == ' ':
			reverse_string.insert(index, ' ')
	return ''.join(reverse_string)


def solve(s):
	a = [i for i in ''.join(s[::-1].split())]
	for i in range(len(s)):
		if s[i] == ' ':
			a.insert(i, ' ')
	return ''.join(a)


import numpy as np

def solve(arg):
	index = 0
	listIndex = []
	while index < len(arg):
		index = arg.find(' ', index)
		if index == -1:
			break
		print('space found at', index)
		listIndex = listIndex + [index]
		index += 1
	print(listIndex)
	arg = arg.replace(' ', '')
	arg = arg[::-1]
	for i in listIndex:
		arg = arg[:i] + ' ' + arg[i:]
		print(i)
	return arg


def solve(s):
	q = ''.join(reversed(s.replace(' ', '')))
	arr = []
	c = 0
	for i in s:
		if i == ' ':
			arr.append(' ')
		else:
			arr.append(q[c])
			c += 1
	return ''.join(arr)


def solve(s):
	spaces = []
	soln = ''
	for i in range(len(s)):
		if s[i] == ' ':
			spaces.append(i)
	for x in s[::-1]:
		if x == ' ':
			continue
		else:
			soln += x
	for x in spaces:
		soln = soln[:x] + ' ' + soln[x:]
	return soln


def solve(s):
	spaces = [i for i in range(len(s)) if s[i] == ' ']
	rev = list(s[::-1].replace(' ', ''))
	for v in spaces:
		rev.insert(v, ' ')
	return ''.join(rev)


def solve(s):
	spaces = []
	string = ''
	for i in range(len(s)):
		if s[i] == ' ':
			spaces.append(i - len(spaces))
	s1 = s.replace(' ', '')
	s1 = list(s1[-1::-1])
	for i in range(len(s1)):
		if i in spaces:
			string += ' '
		string += s1.pop(0)
	return string + ' ' if s[-1] == ' ' else string


def solve(s):
	spaces = []
	count = 0
	for i in [c for c in s]:
		if i.isalpha():
			count += 1
		else:
			spaces.append(count)
			count += 1
	a = s.replace(' ', '')
	b = list(a)
	c = b[::-1]
	d = c
	for x in spaces:
		d.insert(x, ' ')
	e = ''.join(d)
	return e


def solve(s):
	rev_s = ''.join(s.replace(' ', '')[::-1])
	result = ''
	for i in s.split():
		result += rev_s[:len(i)] + ' '
		rev_s = rev_s[len(i):]
	result = result.strip()
	return result + ' ' if len(s) != len(result) else result