0/1 Knapsack Problem
You've broken into an art gallery and want to maximize the value of the paintings you steal. All the paintings you steal you place in your bag which can hold at most W pounds. Given that the weight and value of the ith painting is given by weights[i] and values[i] respectively, return the maximum value you can steal.
3Sum
Given a list of integers, nums, return a list containing all triplets that sum to zero.
Assign Cake
This question is asked by Amazon. You are at a birthday party and are asked to distribute cake to your guests. Each guest is only satisfied if the size of the piece of cake they're given matches their appetite (i.e., is greater than or equal to their appetite). Given two arrays, appetite and cake where the ith element of appetite represents the ith guest's appetite, and the elements of cake represents the sizes of cake you have to distribute, return the maximum number of guests that you can satisfy.
Best Time to Buy and Sell Stock II
You are given the list of prices of a particular stock. Each element in the array represents the price of the stock at a given second throughout the current day. Return the maximum profit you can make trading this stock.
Boats to Save People
This question is asked by Amazon. A ship is about to set sail and you are responsible for its safety precautions. More specifically, you are responsible for determining how many life rafts to carry onboard. You are given a list of all the passengers' weights and are informed that a single life raft has a maximum capacity of limit and can hold at most two people. Return the minimum number of life rafts you must take onboard to ensure the safety of all your passengers.
Bricks in Wheelbarrow
You are transporting bricks on a construction site and want to work as efficiently as possible. The weight of each brick is given by bricks[i]. Given a wheelbarrow that can carry up to (not including) 5000 pounds, return the maximum number of bricks you can place in your wheelbarrow to transport.
Coin Change
This question is asked by Facebook. Given an array that represents different coin denominations and an amount of change you need to make, return the fewest number of coins it takes to make the given amount of change.
Combination Sum
This question is asked by Apple. Given a list of positive numbers without duplicates and a target number, find all unique combinations of the numbers that sum to the target.
Container With Most Water
You are building a pool in your backyard and want to create the largest pool possible. The largest pool is defined as the pool that holds the most water. The workers you hired to dig the hole for your pool didn't do a great job and because of this the depths of the pool at different areas are not equal. Given an integer array of non-negative integers that represents a histogram of the different heights at each position of the hole for your pool, return the largest pool you can create.
Contains Duplicate II
This question is asked by Google. Given an array, nums, and an integer k, return whether or not two unique indices exist such that nums[i] = nums[j] and the two indices i and j are at most k elements apart.
Count Partners
Given an integer array nums, return the total number of "partners" in the array.
Find All Duplicates in Array
Given an array of integers nums, each element in the array either appears once or twice. Return a list containing all the numbers that appear twice.
First Bad Version
This question is asked by Facebook. Releasing software can be tricky and sometimes we release new versions of our software with bugs. When we release a version with a bug it's referred to as a bad release. Your product manager has just informed you that a bug you created was released in one of the past versions and has caused all versions that have been released since to also be bad. Given that your past releases are numbered from zero to N and you have a helper function isBadRelease(int releaseNumber) that takes a version number and returns a boolean as to whether or not the given release number is bad, return the release number that your bug was initially shipped in.
Friend Circles
This question is asked by Facebook. You are given a two dimensional matrix, friends, that represents relationships between coworkers in an office. If friendsi = 1 then coworker i is friends with coworker j and coworker j is friends with coworker i. Similarly if friendsi = 0 then coworker i is not friends with coworker j and coworker j is not friend with coworker i. Friendships in the office are transitive (i.e., if coworker one is friends with coworker two and coworker two is friends with coworker three, coworker one is also friends with coworker three). Given the friendships in the office defined by friends, return the total number of distinct friends groups in the office.
Frog Jump
A frog is attempting to cross a river to reach the other side. Within the river, there are stones located at different positions given by a stones array (this array is in sorted order). Starting on the first stone (i.e. stones[0]), the frog makes a jump of size one potentially landing on the next stone. If the frog's last jump was of size x, the frog's next jump may be of size x - 1, x, or x + 1. Given these following conditions return whether or not the frog can reach the other side.
K Closest Points to Origin
Given a list of points, return the k closest points to the origin (0, 0).
Keyboard Row
Given a list of words, return all the words that require only a single row of a keyboard to type.
Kth Largest Element in an Array
Given an array of integers, nums, and a value k, return the kth largest element.
Labeled Items Maximum Sum
You are given a list of values and a list of labels. The ith element in labels represents the label of the ith element. Similarly, the ith element in values represents the value associated with the ith element (i.e. together, an "item" could be thought of as a label and a price).
Largest Pond Size
You are given a two-dimensional matrix that represents a plot of land. Within the matrix there exist two values: ones which represent land and zeroes which represent water within a pond. Given that parts of a pond can be connected both horizontally and vertically (but not diagonally), return the largest pond size.
Last Stone Weight
This question is asked by Amazon. You are given a group of stones, all of which have a positive weight. At each turn, we select the heaviest two stones and smash them together. When smashing these two stones together, one of two things can happen:
Lemonade Change
This question is asked by Amazon. You're running a popsicle stand where each popsicle costs $5. Each customer you encountered pays with either a $5 bill, a $10 bill, or a $20 bill and only buys a single popsicle. The customers that come to your stand come in the ordered given by the customers array where customers[i] represents the bill the ith customer pays with. Starting with $0, return whether or not you can serve all the given customers while also giving the correct amount of change.
Majority Element
High school students are voting for their class president and you're tasked with counting the votes. Each presidential candidate is represented by a unique integer and the candidate that should win the election is the candidate that has received more than half the votes. Given a list of integers, return the candidate that should become the class president.
Max Area of Island
Given a 2D array grid, where zeroes represent water and ones represent land, return the size of the largest island.
Maximum Length of Concatenated String with Unique Characters
Given an array of words, return the length of the longest phrase, containing only unique characters, that you can form by combining the given words together.
Maximum Points You Can Obtain
This question is asked by Google. You are given a bag of coins, an initial energy of E, and want to maximize your number of points (which starts at zero). To gain a single point you can exchange coins[i] amount of energy (i.e. if I have 100 energy and a coin that has a value 50 I can exchange 50 energy to gain a point). If you do not have enough energy you can give away a point in exchange for an increase in energy by coins[i] amount (i.e. you give away a point and your energy is increased by the value of that coin: energy += coins[i]). Return the maximum number of points you can gain.
Merge Intervals
Given a list of interval objects, merge all overlapping intervals and return the result.
Min Cost Climbing Stairs
This question is asked by Apple. Given a staircase where the ith step has a non-negative cost associated with it given by cost[i], return the minimum cost of climbing to the top of the staircase. You may climb one or two steps at a time and you may start climbing from either the first or second step.
Minimum Path Sum
This question is asked by Google. Given an N×M matrix, grid, where each cell in the matrix represents the cost of stepping on the current cell, return the minimum cost to traverse from the top-left hand corner of the matrix to the bottom-right hand corner.
Missing Number
This question is asked by Amazon. Given an array that contains all distinct values from zero through N except one number, return the number that is missing from the array.
Monotonic Array
This question is asked by Facebook. Given an array nums, return whether or not its values are monotonically increasing or monotonically decreasing.
Move Zeroes
This question is asked by Apple. Given an array of numbers, move all zeroes in the array to the end while maintaining the relative order of the other numbers.
Number of Islands
Given a 2D array of integers with ones representing land and zeroes representing water, return the number of islands in the grid.
Number of Ships in Harbor
You're about to set sail off a pier and first want to count the number of ships that are already in the harbor. The harbor is deemed safe to sail in if the number of boats in the harbor is strictly less than limit. Given a 2D array that presents the harbor, where O represents water and S represents a ship, return whether or not it's safe for you to set sail.
Paint House
This question is asked by Apple. You are tasked with painting a row of houses in your neighborhood such that each house is painted either red, blue, or green. The cost of painting the ith house red, blue or green, is given by costsi, costsi, and costsi respectively. Given that you are required to paint each house and no two adjacent houses may be the same color, return the minimum cost to paint all the houses.
Path with Maximum Gold
This question is asked by Amazon. Given a 2D matrix that represents a gold mine, where each cell's value represents an amount of gold, return the maximum amount of gold you can collect given the following rules:
Plus One
Given an array digits that represents a non-negative integer, add one to the number and return the result as an array.
Predict the Winner
This question is asked by Amazon. Given an integer array, two players take turns picking the largest number from the ends of the array. First, player one picks a number (either the left end or right end of the array) followed by player two. Each time a player picks a particular number, it is no longer available to the other player. This picking continues until all numbers in the array have been chosen. Once all numbers have been picked, the player with the larger score wins. Return whether or not player one will win.
Product of Array Except Self
Given an integer array nums, return an array where each element i represents the product of all values in nums excluding nums[i].
Rabbit Holes Distance
Given a 2D array containing only the following values: -1, 0, 1 where -1 represents an obstacle, 0 represents a rabbit hole, and 1 represents a rabbit, update every cell containing a rabbit with the distance to its closest rabbit hole.
Remove Element
Given an integer array nums and a value val, remove all instances of val in-place and return the length of the new array.
Remove Vowels from String
This question is asked by Amazon. Given a string s, remove all the vowels it contains and return the resulting string.
Reverse Words in a String
Given a string s, reverse the words.
Rotate Image
Given an image represented as a 2D array of pixels, return the image rotated 90 degrees clockwise.
Rotting Oranges (Infection Spread)
Given a 2D array where each cell can have one of three values:
Shortest Distance to Character
Given a string s and a character c, return an array of integers where each index is the shortest distance from the character at that position to the nearest occurrence of c in the string.
Sort Array By Parity II
This question is asked by Amazon. Given an array of integers, nums, sort the array in any manner such that when i is even, nums[i] is even and when i is odd, nums[i] is odd.
Spiral Matrix
Given a 2D matrix, return a list containing all of its elements in spiral order.
String Compression
This question is asked by Facebook. Given a character array, compress it in place and return the new length of the array.
Third Maximum Number
Given an array nums, return the third largest (distinct) value.
Transpose Matrix
Given a 2D matrix nums, return the matrix transposed.
Two City Scheduling
This question is asked by Google. A company is booking flights to send its employees to its two satellite offices A and B. The cost of sending the ith employee to office A and office B is given by pricesi and pricesi respectively. Given that half the employees must be sent to office A and half the employees must be sent to office B, return the minimum cost the company must pay for all their employees' flights.
Two Sum
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.
Word Search
This question is asked by Amazon. Given a 2D board that represents a word search puzzle and a string word, return whether or the given word can be formed in the puzzle by only connecting cells horizontally and vertically.