FastPrepFirst One in a Sorted Binary Array
Problems/First One in a Sorted Binary Array

First One in a Sorted Binary Array

JP Morgan Chase logoJP Morgan Chase● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a JP Morgan Chase new grad onsite interview. The report asks for the first one in a sorted binary array without a linear scan. We chose the index as the result, what to return when there is none, and a size limit. Our version is about 95% the same as the reported question.

The integer array nums contains only zeros and ones, sorted in nondecreasing order. Return the index of its first one.

For this exercise, assume indices start at zero and return -1 when the array contains no one, including when it is empty.

Find the answer in logarithmic time.

Function

firstOne(nums: int[]) → int

Examples

Example 1

nums = [0,0,1,1]return = 2

Indices 0 and 1 contain zero, and index 2 contains the first one.

Example 2

nums = [0,0,0]return = -1

There is no one in the array, so return -1.

Example 3

nums = [1,1]return = 0

The first element is already one, at index 0.

Constraints

  • 0 <= nums.length <= 10000
  • 0 <= nums[i] <= 1
  • nums is sorted in nondecreasing order.

More JP Morgan Chase Onsite Interview questions

  • LFU CacheONSITE INTERVIEW · Seen Nov 2026
  • LRU CacheONSITE INTERVIEW · Seen Nov 2026
  • Employees Above Average SalaryONSITE INTERVIEW · Seen Sep 2026
  • Highest-Earning Employees By DepartmentONSITE INTERVIEW · Seen Sep 2026
  • K Largest Integers in Descending OrderONSITE INTERVIEW · Seen Aug 2026
  • Tile a Three-Row Board with DominoesONSITE INTERVIEW · Seen Jan 2026
  • Two SumONSITE INTERVIEW · Seen Nov 2025
  • Intersection of Two ListsONSITE INTERVIEW · Seen Jan 2025
  • Maximum Subarray SumONSITE INTERVIEW · Seen Jan 2025
  • Fibonacci NumberONSITE INTERVIEW · Seen Nov 2024

Similar questions at other companies

  • Roll a Weighted DieLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Implement Binary SearchQualys · ONSITE INTERVIEWQualys interview questions
  • Messages in an Inclusive Timestamp RangeAttentive · PHONE SCREEN · ONSITE INTERVIEWAttentive interview questions
  • Count Occurrences in a Sorted ArrayAdobe · PHONE SCREEN · ONSITE INTERVIEWAdobe interview questions
  • Closest Version DateAmazon · ONSITE INTERVIEW
  • Count Points in Each Boundary IntervalBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Recursive Binary SearchEPAM · ONSITE INTERVIEWEPAM interview questions
  • Find Unmet Users With Shared InterestsPalantir · ONSITE INTERVIEWPalantir interview questions
  • Find Maximum Frequency of NumberGoogle · ONSITE INTERVIEWGoogle interview questions
  • Song Duration Pairs Divisible by 60The Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions

Interview reports that mention this question

  • JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)

JP Morgan Chase interview experiences

  • JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
  • JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
  • JP Morgan Chase Data and AI Intern Superday: 11 Experiences
  • JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)
  • JPMorgan Code for Good India: 10 Experiences (Part 4 of 5)
All JP Morgan Chase interview questionsSee JP Morgan Chase hiring insights
Saved
class Solution {
    public int firstOne(int[] nums) {
        // Write your code here.
    }
}
Checking account…