Saltar al contenido principal

19 documentos etiquetados con "two-pointers"

Ver Todas las Etiquetas

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.

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.

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.

Happy Number (Magical Number)

Given an integer n, return whether or not it is a "magical" number. A magical number is an integer such that when you repeatedly replace the number with the sum of the squares of its digits, it eventually becomes one.

Is Subsequence

This question is asked by Google. Given two strings s and t, return whether or not s is a subsequence of t.

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.

Palindrome Check

Given a string s, return true if it is a palindrome, and false otherwise. Ignore non-alphanumeric characters and case.

Partition Labels

Given a string s containing only lowercase characters, return a list of integers representing the size of each substring you can create such that each character in s only appears in one substring.

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.

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.

String Compression

This question is asked by Facebook. Given a character array, compress it in place and return the new length of the array.

Two Sum IV - Input is a BST

Given the reference to the root of a binary search tree and a target value, return whether or not two individual values within the tree can sum to the target.