Leetcode 0621. Task Scheduler

Posted on Sun 08 December 2024 in Leetcode • Tagged with greedy, math

Question Link : https://leetcode.com/problems/task-scheduler/

Difficulty: Medium

Premium: False

Question

You are given an array of CPU tasks, each labeled with a letter from A to Z, and a number n. Each CPU interval can be idle or allow the completion of one task. Tasks can be completed …


Continue reading

Leetcode 0277. Find the Celebrity

Posted on Tue 03 December 2024 in Leetcode Premium • Tagged with greedy

Question Link : https://leetcode.com/problems/find-the-celebrity/

Difficulty: Medium

Premium: True

Question

Suppose you are at a party with n people labeled from 0 to n - 1 and among them, there may exist one celebrity. The definition of a celebrity is that all the other n - 1 people know the …


Continue reading

Leetcode 2405. Optimal Partition of String

Posted on Mon 03 April 2023 in Leetcode • Tagged with string, greedy

Question Link : https://leetcode.com/problems/optimal-partition-of-string/

Difficulty: Medium

Premium: False

Question

Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once. Return the minimum number of …


Continue reading

Leetcode 0881. Boats to Save People

Posted on Sun 02 April 2023 in Leetcode • Tagged with two-pointers, greedy

Question Link : https://leetcode.com/problems/boats-to-save-people/

Difficulty: Medium

Premium: False

Question

You are given an array people where people[i] is the weight of the ith person, and an infinite number of boats where each boat can carry a maximum weight of limit. Each boat carries at most two …


Continue reading

Leetcode 0435. Non-overlapping Intervals

Posted on Sun 13 November 2022 in Leetcode • Tagged with interval-merge, greedy

Question Link : https://leetcode.com/problems/non-overlapping-intervals/

Difficulty: Medium

Question

Given an array of intervals intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.   Example 1:

Input: intervals = [[1,2],[2,3],[3,4],[1 …


Continue reading

Leetcode 0495. Teemo Attacking

Posted on Sun 13 November 2022 in Leetcode • Tagged with greedy, interval-merge, simulation

Question Link : https://leetcode.com/problems/teemo-attacking/

Difficulty: Easy

Question

Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly duration seconds. More formally, an attack at second t will mean Ashe is poisoned during the inclusive time interval …


Continue reading

Leetcode 1710. Maximum Units on a Truck

Posted on Fri 01 July 2022 in Leetcode • Tagged with greedy

Question Link : https://leetcode.com/problems/maximum-units-on-a-truck/

Difficulty: Easy

Question

You are assigned to put some amount of boxes onto one truck. You are given a 2D array boxTypes, where boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerBoxi]:

numberOfBoxesi is the number of boxes of type i. numberOfUnitsPerBoxi is the number of units in …


Continue reading

Leetcode 0946. Validate Stack Sequences

Posted on Tue 15 March 2022 in Leetcode • Tagged with stack, simulation, greedy

Question Link : https://leetcode.com/problems/validate-stack-sequences/

Difficulty: Medium

Question

Given two integer arrays pushed and popped each with distinct values, return true if this could have been the result of a sequence of push and pop operations on an initially empty stack, or false otherwise.   Example 1:

Input: pushed …


Continue reading