Given a list of different right and left foot shoes, write a python code to return the exact number of shoe pairs which can be formed from the given list. Also, return how many number of shoes of which foot are required to form pairs with the unpaired shoes.
Input Format
Input_list = ['R','L','L','R','R',R','R,'L']
Constraints
.
Output Format
Paired: 3
Unpaired: 2
Required left Shoes
Sample Input 0
8
L R L L R L R L
Sample Output 0
Paired: 3
Unpaired: 2
Required right shoes
Sample Input 1
9
R L R L R R L R R
Sample Output 1
Paired: 3
Unpaired: 3
Required left shoes
Sample Input 2
6
R R R R R R
Sample Output 2
Paired: 0
Unpaired: 6
Required left shoes
Sample Input 3
8
L L R L R R L R
Sample Output 3
Paired: 4
Unpaired: 0
def paired_shoes(L):
left = right = 0
for shoe in L:
if shoe == 'R':
right += 1
if shoe == 'L':
left += 1
paired = min(left, right)
unpaired = max(left, right) - paired
if left > right:
shoes = 'left'
elif right > left:
shoes = 'right'
else:
shoes = None
return paired, unpaired, shoes
def main():
n = int(input())
line = input()
L = line.split()
paired, unpaired, shoes = paired_shoes(L)
print('Paired:', paired)
print('Unpaired:', unpaired)
if shoes is not None:
print('Required', shoes, 'shoes')
main()
Comments
Leave a comment