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
Minimum Operations by Digit Reversal
00:00
5 left

Minimum Operations by Digit Reversal

MediumPython

Problem

Given an integer array, find the minimum number of operations to make all numbers equal by reversing any digit.

In one operation, choose a distinct value and reverse the digits of every occurrence of that value. Return the minimum operations, or -1 if no common target is reachable. For example, [10, 1, 10] returns 1, because reversing the value 10 changes both occurrences to 1.

Input: a nonempty list nums of nonnegative integers. Output: an integer.

Examples: [12, 21, 12] returns 1; [7, 7, 7] returns 0.

Constraints: 1 <= len(nums) <= 1000, and 0 <= nums[i] <= 10^9.

Constraints

  • 1 <= len(nums) <= 1000
  • 0 <= nums[i] <= 10^9
  • An operation reverses every occurrence of one selected distinct value
  • Leading zeroes produced by reversal are discarded

Function Signature

def min_operations(nums):
Interviewer

Your question is Minimum Operations by Digit Reversal. 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.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.