Answer:
Explanation:
Let's do this in python 3. The logic is simple, we begin by counting the number of each of the command and compare them. If the number of Up (U) commands is the same as the number of Down (D) command AND the number of Left (L) command is the same as the number of Right (R) command, then return True, otherwise return false.
def theRoundTrip(movements):
up_count = movements.count('U')
down_count = movements.count('D')
left_count = movements.count('L')
right_count = movements.count('R')
move_count = len(movements)
if up_count + down_count + left_count + right_count < move_count:
# check if there are anything other than 'UDLW', if true, then print bad input
print('bad input')
return false
else:
return (up_count == down_count) and (left_count == right_count)