All Posts

Leetcode 1785: Minimum Elements to Add to Form a Given Sum

You are given an integer array nums and two integers limit and goal. The elements of the array nums have a property such that abs(nums[i]) <= limit. Your task is to determine the minimum number of elements you need to add to the array in order to make the sum equal to goal. The added elements must also satisfy the condition that their absolute value is less than or equal to limit.

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 1797: Design Authentication Manager

You are tasked with creating an authentication system that handles tokens. Each token has an expiration time, and a user can generate new tokens or renew existing ones before they expire. The system should track and count the number of unexpired tokens at any given time.

Leetcode 1798: Maximum Number of Consecutive Values You Can Make

You are given an integer array ‘coins’, where each element represents the value of a coin you own. You can use these coins to create sums of values starting from 0. Your task is to find the maximum number of consecutive integer values starting from 0 that you can make with your coins.

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.