FastPrepLeftmost Binary Search Match
Problems/Leftmost Binary Search Match

Leftmost Binary Search Match

ByteDance logoByteDance● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A ByteDance interview report names this task as implementing binary search with careful edge cases. The report does not give a full set of rules we can check, so we chose them. Use a sorted integer array and a target. Return the leftmost matching index, or -1. Keep the search at logarithmic time.

Return the smallest index whose value equals target in the nondecreasing array nums, or -1 when the target is absent.

Function

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

Examples

Example 1

nums = [1,2,2,2,4]target = 2return = 1

The first of three equal values is at index one.

Example 2

nums = [1,3,5]target = 2return = -1

The lower-bound position does not contain the target.

Constraints

  • 0 <= nums.length <= 100000
  • nums is sorted in nondecreasing order.
  • The required time complexity is O(log n).

More ByteDance Phone Screen questions

  • Count N-Queens PlacementsPHONE SCREEN · Seen Nov 2026
  • Matrix EscapePHONE SCREEN · Seen Nov 2026
  • Largest Number Below N from Reusable DigitsPHONE SCREEN · Seen Nov 2026
  • Log Analyzer: Busiest Service in a Rolling WindowPHONE SCREEN · Seen Nov 2026
  • Majority ElementPHONE SCREEN · Seen Nov 2026
  • Valid ParenthesesPHONE SCREEN · Seen Nov 2026
  • Binary Tree Target-Sum PathsPHONE SCREEN · Seen Nov 2026
  • Longest Increasing SubsequencePHONE SCREEN · Seen Nov 2026
  • Alien DictionaryPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lexicographically Smallest Topological OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • First Element Greater Than KMeta · PHONE SCREENMeta interview questions
  • 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
  • Target Sum Across Two Sorted ArraysSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
  • Count Occurrences in a Sorted ArrayAdobe · PHONE SCREEN · ONSITE INTERVIEWAdobe interview questions
  • Find the First Target IndexSuperhuman · PHONE SCREENSuperhuman interview questions
  • First Target IndexGrammarly · PHONE SCREEN
  • Ceiling Value in a Sorted ArrayPeopleStrong · PHONE SCREENPeopleStrong interview questions

ByteDance interview experiences

  • ByteDance TikTok USDS SWE Intern Interview: 1 Experience
  • ByteDance MLE New Grad Interviews: 1 Experience
  • ByteDance Security SRE Intern Phone Screens: 1 Experience
  • ByteDance USDS New Grad SWE Phone Screen: 1 Experience
  • ByteDance New Grad Data Engineer Video Interviews: 1 Experience
  • ByteDance Trust & Safety Research Scientist Intern: 1 Experience
All ByteDance interview questionsSee ByteDance hiring insights
Saved
class Solution {
    public int leftmostIndex(int[] nums, int target) {
      // Write your code here.
    }

}
Checking account…