All Posts

Leetcode 162: Find Peak Element

You are given a list of integers, nums. A peak element is an element that is strictly greater than its neighbors. You need to find and return the index of any peak element in the list. The algorithm should run in O(log n) time.

Leetcode 167: Two Sum II - Input Array Is Sorted

Given a sorted array of integers, find two numbers whose sum equals a target value. Return the indices of these two numbers, ensuring they are 1-indexed.

Leetcode 209: Minimum Size Subarray Sum

Given an array of positive integers and a target value, find the minimal length of a contiguous subarray whose sum is greater than or equal to the target. If no such subarray exists, return 0.

Leetcode 268: Missing Number

Given an array nums containing n distinct numbers, each in the range [0, n], return the only number in the range that is missing from the array.

Leetcode 278: First Bad Version

You are managing a product development process where each version of the product is based on its previous version. However, you have a version that failed the quality check. Since all subsequent versions are based on the previous ones, they also fail the quality check. Your task is to find the first bad version that caused all subsequent versions to be bad. You are given an API bool isBadVersion(version) that returns true if the version is bad, and false otherwise. Your goal is to find the first bad version while minimizing the number of calls to the API.

Leetcode 287: Find the Duplicate Number

You are given an array nums of n + 1 integers where each integer is in the range [1, n]. The array contains exactly one duplicate number. Find and return this duplicate number without modifying the array and using constant extra space.