Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Round-Robin Product Ranking
00:00
5 left

Round-Robin Product Ranking

MediumPython

Problem

The Visa Developer Center may need to display products from multiple companies in a balanced order. Given several companies and their products, return product names ordered by descending rating within each company, while selecting products in round-robin order across companies.

Process companies from index 0 through n - 1. In each round, select the next highest-rated remaining product from every company that still has products. Continue until all products have been selected. If ratings are equal within one company, preserve their original input order.

Formal Specification

Implement round_robin_products(companies), where companies is a list of companies, and each company is a list of products represented as [product_name, rating]. Return a list of product names. The input list must not be modified.

Constraints

  • 1 <= len(companies) <= 10^4
  • The total number of products is at most 10^5
  • Product names are non-empty strings
  • 0 <= rating <= 10^9
  • Product names are unique across all companies

Function Signature

def round_robin_products(companies):
Interviewer

Your question is Round-Robin Product Ranking. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.