All Posts

Leetcode 2391: Minimum Amount of Time to Collect Garbage

You are given an array of strings garbage where each string represents the garbage collected at a specific house. The characters ‘M’, ‘P’, and ‘G’ represent metal, paper, and glass garbage, respectively. The time to collect one unit of garbage is 1 minute. You are also given an array travel where each element represents the time required to travel between two consecutive houses. Three trucks are responsible for picking up different types of garbage and can only travel sequentially from house 0 to the end. Each truck only collects one type of garbage and each truck can only be used one at a time. Return the minimum time required to pick up all the garbage.

Leetcode 2399: Check Distances Between Same Letters

You are given a string s consisting of lowercase English letters where each letter appears exactly twice. You are also given an array distance of length 26, where each element represents the number of characters between the two occurrences of the corresponding letter (0-indexed, ‘a’ corresponds to index 0, ‘b’ to index 1, etc.). Your task is to determine if the string s is a ‘well-spaced’ string. A string is well-spaced if, for each letter in s, the number of characters between its two occurrences matches the corresponding value in the distance array.

Leetcode 2405: Optimal Partition of String

You are given a string s. Your task is to partition this string into the fewest number of substrings such that no character appears more than once in each substring. Each character must belong to exactly one substring in the partition.

Leetcode 2409: Count Days Spent Together

Alice and Bob are traveling to Rome for separate business meetings. You are given four strings representing their travel dates: arriveAlice, leaveAlice, arriveBob, and leaveBob. Each string follows the format ‘MM-DD’, which represents the month and day of their respective travel dates. Alice will be in Rome from ‘arriveAlice’ to ’leaveAlice’, while Bob will be in the city from ‘arriveBob’ to ’leaveBob’. Your task is to calculate how many days they will both be in Rome together.

Leetcode 2414: Length of the Longest Alphabetical Continuous Substring

Given a string ’s’ consisting of lowercase English letters, find the length of the longest substring where the characters are consecutive in the alphabet.

Leetcode 2418: Sort the People

Given two arrays, one containing the names and the other containing the corresponding heights of people, return the names sorted in descending order by their heights.