This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param {number[][]} grid - A 2D matrix sorted in non-increasing order | |
| * @return {number} - Total count of negative numbers in the matrix | |
| */ | |
| var countNegatives = function (grid) { | |
| let count = 0; | |
| // Loop through each row | |
| for (let row = 0; row < grid.length; row++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Given a string of 'Y' (customer arrives) and 'N' (no customer), | |
| * find the hour to close the shop that minimizes penalty. | |
| * | |
| * Penalty rules: | |
| * - Staying open while no customers come → +1 penalty for each 'N' | |
| * - Closing early while customers would have come → +1 penalty for each 'Y' | |
| * | |
| * @param {string} customers | |
| * @return {number} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param {number[]} apple | |
| * @param {number[]} capacity | |
| * @return {number} | |
| */ | |
| var minimumBoxes = function(apple, capacity) { | |
| // 1. Compute the total number of apples across all packs. | |
| // Since aplles can be split across boxes, only the total matters. | |
| let totalApples = 0; | |
| for (let a of apple) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param {string[]} strs | |
| * @return {number} | |
| */ | |
| var minDeletionSize = function(strs) { | |
| const n = strs.length; // number of rows | |
| const m = strs[0].length; // number of columns (all strings same length) | |
| // dp[i] = length of the longest valid chain ending at column i | |
| const dp = Array(m).fill(1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param {string[]} strs | |
| * @return {number} | |
| */ | |
| var minDeletionSize = function(strs) { | |
| const n = strs.length; | |
| const m = strs[0].length; | |
| // sorted[i] = true means strs[i] < strs[i+1] is already determined | |
| const sorted = Array(n - 1).fill(false); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param {string[]} strs | |
| * @return {number} | |
| */ | |
| var minDeletionSize = function(strs) { | |
| // Number of rows (strings) | |
| const n = strs.length; | |
| // Number of columns (length of each string) | |
| const m = strs[0].length; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param {number} n | |
| * @param {number[][]} meetings | |
| * @param {number} firstPerson | |
| * @return {number[]} | |
| */ | |
| // Function to find all people connected to the first person | |
| var findAllPeople = function(n, meetings, firstPerson) { | |
| // Initialize an array to keep track of connections | |
| const connected = new Array(n).fill(-1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Calculates the maximum profit achievable by applying a strategy | |
| * and replacing a window of size `k` with a new profit calculation. | |
| * | |
| * @param {number[]} prices - Array of prices over time. | |
| * @param {number[]} strategy - Strategy multipliers applied to each price. | |
| * @param {number} k - Size of the window to adjust. | |
| * @returns {number} Maximum profit achievable. | |
| */ | |
| var maxProfit = function(prices, strategy, k) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param {number[]} prices | |
| * @param {number} k | |
| * @return {number} | |
| */ | |
| var maximumProfit = function(prices, k) { | |
| // Edge cases | |
| const n = prices.length; | |
| if (n === 0 || k === 0) return 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param {number} n | |
| * @param {number[]} present | |
| * @param {number[]} future | |
| * @param {number[][]} hierarchy | |
| * @param {number} budget | |
| * @return {number} | |
| */ | |
| var maxProfit = function(n, present, future, hierarchy, budget) { | |
| const employeeCount = n; |
NewerOlder