# Posts with tag 'greedy'

## Fractional Knapsack

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

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

## Lexicographically Smallest Non-Palindromic String

You are given a lowercase alphabet string s that is a palindrome. Update one character such that s is no longer a palindrome and is lexicographically smallest.

## Maximum Absolute Value of Sublist

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

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...

## Lexicographically Smallest String of Distance K

A distance of a lowercase alphabet character is defined to be its index (1-indexed) in the alphabet. For example "a" is 1, "b" is 2 and "z" is 26. The distan...

## Longest Interval

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

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

## Interval Duration

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

## Largest Sublist Sum

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

## Three Player Coin Game

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

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

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

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

## Max Product of Three Numbers

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

## K Numbers Greater Than or Equal to K

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

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

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

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

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

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