Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Delete Number From Array

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Delete Number From Array. Start with the requirements on the right.

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.

Problem

FlexTrade Systems Inc. processes fixed-size numeric buffers for market-data calculations. Given a static array of integers and a target value, remove every occurrence of the target in place, preserving the relative order of all remaining elements.

Formal Specification

Implement remove_all(nums, target). The function receives nums, a mutable list of integers, and target, an integer. Compact the retained values into the beginning of nums, truncate the list to the new logical length, and return the resulting list. Do not create another list proportional to the input size.

If the target does not occur, leave the array unchanged. If every element equals the target, return an empty list.

Constraints

  • 0 <= nums.length <= 10^5
  • -10^9 <= nums[i], target <= 10^9
  • The input list is mutable
  • Retained values must preserve their original relative order
  • Auxiliary space must be O(1), excluding the returned list representation

Function Signature

def remove_all(nums, target):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output