FastPrepBinary Search
Problems/Binary Search

Binary Search

Capital One logoCapital One● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Binary search is named outright in two Capital One reports, a 2020 one from a software engineer and a 2021 one from a software developer, who could code it in whatever language they liked.

No input format, output or limits are given. In this version the values strictly increase from left to right, and the answer is the target's position counting from 0, or -1 if it is absent. The limits are our choice.

Our version is about 90% the same as the reported questions.

The numbers in nums go up from left to right, and no number appears twice. Find target: give its position, counting from 0, or -1 when it is missing.

Here n is the length of nums. Try to look at only about log2(n) of the numbers. A plain left-to-right scan is also fast enough for these limits.

Function

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

Examples

Example 1

nums = [-40,-12,3,18,26,51,77,90,104]target = 104return = 8

104 is the last of the nine values, so its position is 8.

Example 2

nums = [-40,-12,3,18,26]target = 20return = -1

20 is bigger than 18 and smaller than 26, and no value in between equals it. It is absent, so return -1.

Example 3

nums = [6,9]target = 6return = 0

The first value, at position 0, is the one we want.

Constraints

  • 1 <= nums.length <= 10^4
  • -10^4 < nums[i], target < 10^4
  • Each value of nums is larger than the one before it.

More Capital One Onsite Interview questions

  • Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
  • Sort ColorsONSITE INTERVIEW · Seen Oct 2026
  • Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
  • Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
  • Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
  • Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
  • Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
  • Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
  • Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025

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

Capital One interview experiences

  • Capital One Coding OA Questions: 3 Experiences
  • Capital One Experienced Engineer Power Day and OA: 6 Experiences
  • Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
  • Capital One TDP Agentic Round (AI Coding): 7 Experiences
  • Capital One SWE Power Day, Level Not Reported: 6 Experiences
  • Capital One TIP Intern OA and Power Day: 13 Experiences
All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public int search(int[] nums, int target) {
        // Write your code here.
    }
}
Checking account…