FastPrepFind the First Target Index
Problems/Find the First Target Index

Find the First Target Index

Superhuman logoSuperhuman● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The source company label is Grammarly while the thread title says Superhuman. This item is placed under Superhuman for now and can be moved without changing either company record or the source history. The source reported only a binary-search task to find a first index, so the rule below about equality with the target is our reading. Our version is about 70% the same as the reported question.

Given a nondecreasing array of integers nums and an integer target, return the smallest index i such that nums[i] == target.

If target does not appear in nums, return -1.

Function

firstIndex(nums: int[], target: int) → int

Examples

Example 1

nums = [1,2,2,2,5,8]target = 2return = 1

The target appears at indices 1, 2, and 3, so the first index is 1.

Example 2

nums = [-5,-1,0,4,4,9]target = 4return = 3

The first value equal to 4 is at index 3.

Example 3

nums = [1,3,5,7]target = 4return = -1

No array value equals 4, so the result is -1.

Constraints

  • 0 <= nums.length <= 10^5.
  • -2^31 <= nums[i], target <= 2^31 - 1.
  • nums is sorted in nondecreasing order.
  • Your algorithm should run in O(log n) time.

More Superhuman interview questions

  • Email Funnel: Opened Within a Day, Replied Within a WeekPHONE SCREEN · Seen Nov 2026
  • Intersect Two Interval ListsPHONE SCREEN · Seen Jul 2026
  • Deep Copy a Random-Pointer ListPHONE SCREEN
  • Deep Copy a Singly Linked ListPHONE SCREEN
  • Recover a Tree from Preorder Depth EncodingPHONE SCREEN
  • Reverse a Singly Linked ListPHONE SCREEN
  • Longest Distinct StringOA · Seen Sep 2026
  • Minimum Time on Two ProcessorsOA · Seen Sep 2026
  • Top Mutual-Friend RecommendationsOA · Seen Sep 2026
  • Lost MessagesOA · Seen Apr 2026

Similar questions at other companies

  • Track New Values in Sorted OrderBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Price at Query TimestampsGoogle · PHONE SCREENGoogle interview questions
  • First Missing Number in a Consecutive ArrayArista Networks · OA · PHONE SCREENArista Networks interview questions
  • Messages in an Inclusive Timestamp RangeAttentive · PHONE SCREEN · ONSITE INTERVIEWAttentive interview questions
  • First Bad Version in a Monotone ArrayMeta · PHONE SCREENMeta interview questions
  • Target Sum Across Two Sorted ArraysSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
  • Leftmost Binary Search MatchByteDance · PHONE SCREENByteDance interview questions
  • Count Occurrences in a Sorted ArrayAdobe · PHONE SCREEN · ONSITE INTERVIEWAdobe interview questions
  • First Target IndexGrammarly · PHONE SCREEN
  • Ceiling Value in a Sorted ArrayPeopleStrong · PHONE SCREENPeopleStrong interview questions
All Superhuman interview questionsSee Superhuman hiring insights
Saved
class Solution {
    public int firstIndex(int[] nums, int target) {
      // write your code here
    }
}
Checking account…