Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find Indexes of Target Number

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

Your question is Find Indexes of Target Number. 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

A Google Search preprocessing step needs to identify every position where a specified token appears in a sequence of encoded values. Given an integer array and a target integer, return all zero-based indexes whose values equal the target.

You must preserve the indexes in ascending order. If the target does not appear, return an empty list.

Formal Specification

Implement find_indices(nums, target):

  • Input: nums, a list of integers, and target, an integer.
  • Output: A list of integers containing every index i such that nums[i] == target.
  • The returned indexes must be in the same left-to-right order as they appear in nums.
  • Do not modify nums.

Constraints

  • 0 <= len(nums) <= 10^5
  • -10^9 <= nums[i] <= 10^9 when nums is non-empty
  • -10^9 <= target <= 10^9
  • Indexes are zero-based
  • The input array must not be modified

Function Signature

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