Array

Gas Station

LeetCode problem #134

Binary Search

Given a sorted array of integers and a target value, return the index of the target if found, or -1 if not present.

Check if Array is Sorted

Determine if an array is sorted in ascending, descending, or not sorted at all

Convert Sorted Array to Binary Search Tree

Convert a sorted array to a height-balanced binary search tree.

Daily Temperatures

Find the number of days until a warmer temperature for each day.

Design Circular Queue

Design a circular queue with fixed size that supports enqueue, dequeue, front, rear, isEmpty, and isFull operations.

Find Duplicate Number

Find the duplicate number in an array containing n+1 integers where each integer is between 1 and n (inclusive)

Find the Maximum Element in an Array

Find and return the largest element in an array of integers

Find the Second Largest Element in an Array

Find and return the second largest element in an array of integers

Implement Queue

Implement a queue using arrays or linked lists with O(1) time complexity for all operations.

Implement Stack

Design and implement a stack data structure with push, pop, top, and empty operations

Maximize Sum After K Negations

Maximize array sum by flipping signs of k elements using greedy heap approach

Median of Two Sorted Arrays

Given two sorted arrays nums1 and nums2, return the median of the two sorted arrays. The overall run time complexity should be O(log(min(m,n))).

Merge Intervals

Given an array of intervals where intervals[i] = [start_i, end_i], merge all overlapping intervals and return an array of the non-overlapping intervals that cover all the intervals in the input.

Merge Two Sorted Arrays (LC 88) — Two Pointers

LeetCode 88 merge sorted array in-place: reverse two pointers (merge from end) in O(m+n) time, O(1) space. Step-by-step + examples.

Missing Number

Find the missing number in an array containing n distinct numbers taken from 0, 1, 2, ..., n.

Move All Zeros to the End

Move all zeros in an array to the end while maintaining the relative order of non-zero elements

Next Greater Element

Find the next greater element for each element in an array.

Reduce Array Size to Half

Find minimum removals to reduce array size by half using greedy heap approach

Reverse an Array

Reverse the order of elements in an array in-place and return the modified array

Rotate Array by K Steps

Rotate an array to the right by k steps where k is non-negative

Search in Rotated Sorted Array

Given a rotated sorted array and a target value, return the index of the target if found in O(log n) time, or -1 if not present.

Sliding Window Maximum

Find the maximum element in each sliding window of size k

Stock Span Problem

Calculate the span of stock prices for each day

Subarray with Given Sum

Find a subarray with a given sum in an array of positive integers.

Trapping Rain Water

Calculate how much rainwater can be trapped between bars of different heights

Two Sum

Find two numbers in an array that add up to a target value.

Two Sum

Given an array of integers and a target, return indices of two numbers that add up to the target.