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); |
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} numberOfUsers | |
| * @param {string[][]} events | |
| * @return {number[]} | |
| */ | |
| var countMentions = function(numberOfUsers, events) { | |
| // Result: mentions per user | |
| const mentions = new Array(numberOfUsers).fill(0); | |
| // Online state and offline-until times |
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[][]} buildings | |
| * @return {number} | |
| */ | |
| var countCoveredBuildings = function(n, buildings) { | |
| // Guard: empty list -> no covered buildings | |
| if (!buildings || buildings.length === 0) return 0; | |
| // Step 1: Precompute extremes per row (y) and column (x). |
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[]} complexity | |
| * @return {number} | |
| */ | |
| var countPermutations = function(complexity) { | |
| const n = complexity.length; | |
| const MOD = 1_000_000_007; // Large prime modulus for preventing overflow | |
| // Check validity: all elements after the first must be strictly greater | |
| for (let i = 1; i < n; i++) { |