Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Identify Heavier Ball
00:00
5 left

Identify Heavier Ball

MediumPython

Problem

Suppose we have 8 balls with identical weight and a heavier one. How many times do you need to use the scale to identify the heavier ball?

Implement minimum_weighings(num_balls) for num_balls identical balls containing exactly one heavier ball. Each balance-scale use compares two groups and has three possible outcomes: left heavier, right heavier, or balanced. Return the minimum worst-case number of weighings needed to guarantee identification.

Constraints

  • 1 <= num_balls <= 10^18
  • Exactly one ball is heavier than all others
  • The scale is a balance scale with three possible outcomes

Function Signature

def minimum_weighings(num_balls):
Interviewer

Your question is Identify Heavier Ball. 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.