Skip to main content

15 docs tagged with "Binary Search"

View All Tags

Binary Search

Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums...

Count of Range Sum

Given an integer array nums and two integers lower and upper, return the number of range sums that lie in [lower, upper] inclusive.

Find K Closest Elements

Given a sorted integer array arr, two integers k and x, return the k closest integers to x in the array.

Find Peak Element

A peak element is an element that is strictly greater than its neighbors.

Find Smallest Letter Greater Than Target

Return the smallest character in letters that is lexicographically greater than target. If such a character does not exist, return the first character in letters.

First Bad Version

Implement a function to find the first bad version. You should minimize the number of calls to the API.

Median of Two Sorted Arrays

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.

Random Pick with Weight

You need to implement the function pickIndex(), which randomly picks an index in the range [0, w.length - 1] (inclusive) and returns it.

Search a 2D Matrix

Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix.

Search a 2D Matrix II

Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix.

Search in Rotated Sorted Array

Given the array nums after the possible rotation and an integer target, return the index of target if it is in nums, or -1 if it is not in nums.

Time Based Key-Value Store

Design a time-based key-value data structure that can store multiple values for the same key at different time stamps and retrieve the key's value at a certain timestamp.