Home » Python » Competitive Coding Questions

# Python Shoes Matching | Competitive Coding Questions

**Python Competitive Coding Questions | Shoes Matching**: This practice is based on Shoes Matching in Python programming language.

Submitted by Prerana Jain, on April 25, 2020

**Question:**

**Zack** has messed up all his shoes. He has * N* shoes (single shoe, not paired). You have to search for the partner of each shoe.

**Find the maximum pair you can make out of them**.

You will be given a description of each shoe i.e. the size of the shoes and if it is left shoes (* L*) or right shoes (

*). Two shoes can be paired if they are having the same size and one is left*

**R***and the other is right*

**L***.*

**R****Input:**

The first line contains a single integer * N*. The number of shoes Next

*lines has a description for each shoe, with spaces, separated size, and*

**N***.*

**L/R**5 1 L 2 R 3 L 1 R 2 L

**Output:**

A single integer, maximum pairs can be made out of the given shoes.

2

**Constraints:**

1<=N<=1000 Shoe size will be a positive integer less than 100.

**Explanation/Solution:**

In this question, we are given a number of shoes with their size and type whether it is left or right. Our aim is to make a pair of shoes which have the same size and one is left and the other is right. So we make two array one have the shoe size and other having the shoe type. Each time we compare the shoe size with other shoes and also check the types of shoes it is left or right the make one pair of shoes.

To solve this question, we are using Python3.

**Code:**

s = int(input()) arr = [ ] brr = [ ] p = s while(s>0): s-=1 a,b = input().split() arr.append(int(a)) brr.append(b) i,j,count=0,0,0 s = p while(i<s-1): j=i+1 while(j<s): if(arr[i]==arr[j] and brr[j]!= brr[i] and brr[j]!='S' and brr[i]!='S'): brr[i]='S' brr[j]='S' count+=1 break j+=1 i+=1 print(count)

**Output**

6 1 L 2 L 3 L 1 R 2 R 3 R 3

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions