Arrays

Algorithms

Thinking About Partitions

Given an array with n objects colored red, white, or blue, sort them in-place in a single pass. Objects of the same color should be adjacent to each other and the sorted colors should be in the order of red, white, and blue.

Read
Algorithms

Longest Subarray with a Sum Constraint

Given an array of numbers A and a key k, find the length of the longest subarray whose sum is less than or equal to k.

Read
Algorithms

Smaller Numbers After Self

You are given an integer array A and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of A[i].

Read
Algorithms

The Skyline Problem

A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Suppose you are given the locations and height of all the buildings in a cityscape. Write a program to output the skyline formed by these buildings.

Read
Algorithms

Kth Smallest Element in Two Sorted Arrays

Given two sorted arrays, find the kth smallest element in the array that would be produced if we combined and sorted them. Array elements may be duplicated within and across the input arrays.

Read
Algorithms

Trapping Rain Water

Given an array of non-negative integers that represent an elevation map where the width of each bar is 1, compute the amount of rainwater that can be trapped within it.

Read
Algorithms

Largest Rectangle In Histogram

Given an array of non-negative integers which represent histogram bar heights, find the area of largest rectangle.

Read
Algorithms

Maximum Profit from K Transactions

You have an array for which the i-th element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most k transactions.

Read