FastPrepImplement Binary Search
Problems/Implement Binary Search

Implement Binary Search

Qualys logoQualys● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Qualys onsite interview. The report asks for a binary search and an analysis of its complexity. We chose a sorted-array interface, that any matching index is fine when values repeat, a value to return when nothing is found, the examples, and the limits.

Given an integer array sorted in nondecreasing order and a target, implement iterative binary search from scratch. Return the index of any occurrence of the target, or -1 when it is absent.

Function

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

Examples

Example 1

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

The target is at index 3.

Example 2

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

The target does not occur.

Constraints

  • 0 <= nums.length <= 100000
  • -10^9 <= nums[i], target <= 10^9
  • nums is sorted in nondecreasing order.

More Qualys Onsite Interview questions

  • Delete a Doubly Linked List Node at a PositionONSITE INTERVIEW · Seen Oct 2026
  • Find the Entry of a Linked List CycleONSITE INTERVIEW · Seen Oct 2026
  • Insert a Doubly Linked List Node at a PositionONSITE INTERVIEW · Seen Oct 2026
  • Rotate an Array Right by K StepsONSITE INTERVIEW · Seen Oct 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Roll a Weighted DieLinkedIn · ONSITE INTERVIEWLinkedIn 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
  • Search a Sorted Array of WordsExpedia · ONSITE INTERVIEWExpedia interview questions
All Qualys interview questionsSee Qualys hiring insights
Saved
class Solution {
    public int binarySearch(int[] nums, int target) {
      // Write your iterative binary search here.
    }

}
Checking account…