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; |
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 | |
| * @return {number} | |
| */ | |
| var getDescentPeriods = function(prices) { | |
| let total = 0; // total number of descent periods | |
| let streak = 0; // length of current descent streak | |
| for (let i = 0; i < prices.length; i++) { | |
| if (i > 0 && prices[i] === prices[i - 1] - 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 number of ways to divide a corridor into valid sections. | |
| * Each section must contain exactly two 'S' (seats). | |
| * 'P' (plants) between pairs of seats determine possible partitions. | |
| * | |
| * @param {string} corridor - A string consisting of 'S' (seats) and 'P' (plants). | |
| * @return {number} - The number of valid ways to divide the corridor. | |
| */ | |
| var numberOfWays = function(corridor) { | |
| const MOD = 1e9 + 7; // Large prime modulus to prevent overflow |
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[]} code | |
| * @param {string[]} businessLine | |
| * @param {boolean[]} isActive | |
| * @return {string[]} | |
| */ | |
| var validateCoupons = function(code, businessLine, isActive) { | |
| // Guard: ensure arrays exist and have equal length | |
| if (!Array.isArray(code) || !Array.isArray(businessLine) || !Array.isArray(isActive)) return []; | |
| const n = Math.min(code.length, businessLine.length, isActive.length); |