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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Move All Occurrences of X
00:00
5 left

Move All Occurrences of X

EasyPython

Problem

AppFolio may need to reorder a property-related array so records with a particular marker value are processed last. Given an integer array nums and an integer x, move every occurrence of x to the end of the array in place, while preserving the relative order of all other values and the relative order of the moved x values.

This is a stable partition, not a cyclic rotation. Return the modified array.

Formal Specification

Implement move_value_to_end(nums, x), where nums is a mutable list of integers and x is an integer. Modify nums directly and return the same list object. The output must contain exactly the same values as the input, with all values not equal to x first, followed by all values equal to x.

Constraints

  • 0 <= nums.length <= 10^5
  • -10^9 <= nums[i], x <= 10^9
  • The solution must use O(1) auxiliary space
  • The relative order of all values must be preserved

Function Signature

def move_value_to_end(nums, x):
Interviewer

Your question is Move All Occurrences of X. 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.