Skip to content

Instantly share code, notes, and snippets.

@GuillermoFarias
Created December 20, 2023 00:18
Show Gist options
  • Save GuillermoFarias/fb303639b31faeb50e471531b9e8754c to your computer and use it in GitHub Desktop.
Save GuillermoFarias/fb303639b31faeb50e471531b9e8754c to your computer and use it in GitHub Desktop.
Toku test
def highest_revenue_item(data):
products = []
rows = data.split()
for row in rows:
row_data = row.split(',')
if len(row_data) != 2:
continue
try:
product_id = int(row_data[0])
price = int(row_data[1])
except ValueError:
continue
product_exists = False
for product in products:
if product[0] == product_id:
product_exists = True
product[1] += 1
break
if not product_exists:
products.append([product_id, 1, price])
highest_revenue = 0
highest_revenue_product_id = 0
for product in products:
revenue = product[1] * product[2]
if revenue > highest_revenue:
highest_revenue = revenue
highest_revenue_product_id = product[0]
return highest_revenue_product_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment