All Posts

Leetcode 1753: Maximum Score From Removing Stones

You are given three piles of stones, with sizes a, b, and c respectively. In each turn, you can choose two different non-empty piles, remove one stone from each, and add 1 point to your score. The game stops when there are fewer than two non-empty piles left, meaning no more valid moves are available. Your task is to return the maximum score you can achieve.

Leetcode 1786: Number of Restricted Paths From First to Last Node

You are given a connected, undirected, weighted graph with n nodes, labeled from 1 to n. An array ’edges’ represents the edges in the graph where each element edges[i] = [ui, vi, weighti] indicates that there is an edge between nodes ui and vi with a weight of weighti. A path from node start to node end is a sequence of nodes [z0, z1, …, zk] such that z0 = start, zk = end, and there is an edge between zi and zi+1 for each 0 <= i <= k-1.

The distance of a path is the sum of the weights of the edges along the path. A restricted path is a path where the distance from node ’n’ to node zi is strictly greater than the distance from node ’n’ to node zi+1 for each 0 <= i <= k-1.

You need to return the number of restricted paths from node 1 to node n, modulo 10^9 + 7.

Leetcode 1792: Maximum Average Pass Ratio

A school has several classes, and each class will have students taking a final exam. You are provided with a 2D array where each class is represented by two values: the number of students who will pass and the total number of students in the class. Additionally, a number of brilliant students, ’extraStudents,’ is provided. These brilliant students are guaranteed to pass if assigned to any class. The goal is to assign these extra students to maximize the average pass ratio of all classes. The pass ratio of a class is defined as the number of students passing divided by the total number of students in the class. You need to return the maximum possible average pass ratio after optimally distributing the extra students.

Leetcode 1801: Number of Orders in the Backlog

You are managing an order system for a marketplace where both buy and sell orders are placed in batches. Each order contains a price, a quantity, and a type (either buy or sell). You need to calculate how many orders remain unfulfilled in the system after processing all the orders.

Leetcode 1834: Single-Threaded CPU

You are given a list of tasks, where each task is represented by a pair of integers: [enqueueTime, processingTime]. The task can only be processed once its enqueueTime has passed. Your goal is to find the order in which tasks are processed by a single-threaded CPU that follows a specific processing strategy.

Leetcode 1845: Seat Reservation Manager

Design a system to manage the reservation state of n seats numbered from 1 to n. Implement the SeatManager class to handle reserving and unreserving seats. The class should be able to return the smallest available seat when reserved, and make seats available again when unreserved.