Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Top 3 Companies by Stock Averages
00:00
5 left

Top 3 Companies by Stock Averages

EasyPython

Problem

A financial insights prototype connected to Shopify Admin receives one week of stock prices for multiple companies. Find the three companies with the highest average stock price over the seven-day period.

Return their zero-based row indices, ordered from highest average to lowest. If two companies have the same average, place the company with the smaller index first.

Formal Specification

Implement top_three_companies(prices), where prices is a non-empty 2D array of numbers. Each row represents one company, and each row contains exactly seven daily prices. Return a list containing up to three integer row indices. If fewer than three companies are provided, return all available indices.

You may compare seven-day totals instead of averages because every company has the same number of days.

Constraints

  • 1 <= len(prices) <= 10^5
  • Each company has exactly 7 daily prices
  • 0 <= prices[i][j] <= 10^9
  • Prices may be integers or floating-point numbers
  • Return at most three indices

Function Signature

def top_three_companies(prices):
Interviewer

Your question is Top 3 Companies by Stock Averages. 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
Sign up free to run your codeLog inLn 2
Run your code to see test output here.