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.