#HackerRank

Publicado em: 23 Março 2025
no canal de: CodeVisium
69
4

In this video, we break down the Shoe Shop problem step-by-step using Python’s collections.Counter.

Steps Explained:

Input Reading:

Read the total number of shoes and the list of shoe sizes.

Build an inventory using collections.Counter.

#InputHandling #Counter

Processing Customers:

Loop through each customer's request.

Check if the desired shoe size is available; if so, add the price to the total earnings and update the inventory.

#Looping #ConditionalLogic

Output:

Print the total earnings after all transactions.

#Output #EarningsCalculation

Copy and paste the code below into your Jupyter Notebook and practice along with the detailed solution!

Code for Detailed Version:

===============================
HackerRank Python: Shoe Shop Problem (Detailed Version)
===============================
Step 1: Read the number of shoes and build the inventory using collections.Counter.
Step 2: Process each customer's purchase:
Check if the desired shoe size is available, then update earnings and inventory.
Step 3: Print the total money earned.

from collections import Counter

def shoe_shop_long():
Read the total number of shoes
n = int(input().strip())

Read the list of shoe sizes and create an inventory counter
shoes = list(map(int, input().split()))
inventory = Counter(shoes)

Initialize total earnings
total = 0

Read the number of customers
customers = int(input().strip())

Process each customer's request
for _ in range(customers):
size, price = map(int, input().split())
If the desired shoe size is available, process the sale
if inventory[size] v 0:
total += price
inventory[size] -= 1 # Reduce inventory for that shoe size
Print the total earnings
print(total)

To run the detailed solution, call:
if _name_ == '__main__':
shoe_shop_long()


Nesta página do site você pode assistir ao vídeo on-line #HackerRank duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário CodeVisium 23 Março 2025, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 69 vezes e gostou 4 espectadores. Boa visualização!