Posts with tag 'greedy'

Fractional Knapsack

1 minute read

You are given two lists of integers weights and values which have the same length and an integer capacity. weights[i] and values[i] represent the weight and ...

Making Change

less than 1 minute read

Find the minimum number of coins required to make n cents.

Maximum Absolute Value of Sublist

less than 1 minute read

You are given a list of integers nums. Return the maximum possible abs(nums[i] + nums[i + 1] + ... + nums[j]) for any i <= j.

Unique String Frequencies

less than 1 minute read

Given a lowercase alphabet string s, return the minimum number of characters that we need to delete such that the frequency of each character occurs a unique...

Longest Interval

less than 1 minute read

You are given a two-dimensional list of integers intervals where each list represents an inclusive [start, end] interval. Return the longest interval that yo...

Interval Union

less than 1 minute read

Given a two-dimensional integer list intervals representing unsorted inclusive intervals, return their union in sorted order.

Interval Duration

less than 1 minute read

You are given a two-dimensional list of integers intervals where each list represents an inclusive [start, end] interval.

Largest Sublist Sum

less than 1 minute read

Given a list of integers nums, return the sum of a non-empty contiguous sublist with the largest sum.

Three Player Coin Game

1 minute read

You are given a list of non-negative integers piles where each piles[i] represents the number of coins on pile i. In each move, you can do the following unti...

Sort List by Reversing Once

1 minute read

You are given a list of integers nums. Given that you can first reverse one sublist in nums, return whether you can make the resulting list be arranged in as...

Smallest Number With No Adjacent Duplicates

less than 1 minute read

You are given a string s containing "1", "2", "3" and "?". Given that you can replace any “?” with "1", "2" or "3", return the smallest number you can make a...

Odd Number of Digits

less than 1 minute read

Given a list of positive integers nums, return the number of integers that have odd number of digits.

Max Product of Three Numbers

less than 1 minute read

Given a list of integers nums, find the largest product of three distinct elements.

K Numbers Greater Than or Equal to K

less than 1 minute read

You are given a list of non-negative integers nums. If there are exactly k numbers in nums that are greater than or equal to k, return k. Otherwise, return -1.

Interval Intersection

1 minute read

Given a two-dimensional integer list intervals of the form [start, end] representing intervals (inclusive), return their intersection, that is, the interval ...

First Fit Room

1 minute read

You are given a list of integers rooms and an integer target. Return the first integer in rooms that’s target or larger. If there is no solution, return -1.

Find Local Peaks

1 minute read

You are given a list of integers nums. Return the index of every peak in the list, sorted in ascending order. An index i is called a peak if:

Equalize List Sums with Minimal Updates

1 minute read

You are given two lists of integers a and b where every element in both lists is between 1 to 6. Consider an operation where you pick a number in either a or...

Consecutive Ones

less than 1 minute read

You are given a list of integers nums which contains at least one 1. Return whether all the 1s appear consecutively.

Buying Cars

less than 1 minute read

Given a list of integers prices representing prices of cars for sale, and a budget k, return the maximum number of cars you can buy.

ASCII String to Integer

less than 1 minute read

You are given a string s containing digits from "0" to "9" and lowercase alphabet characters. Return the sum of the numbers found in s.

Back to top ↑