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[]} nums | |
| * @param {number} k | |
| * @return {boolean} | |
| */ | |
| var hasIncreasingSubarrays = function(nums, k) { | |
| // Helper function to check if a subarray is strictly increasing | |
| function isStrictlyIncreasing(start, end) { | |
| for (let i = start; i < end; i++) { | |
| if (nums[i] >= nums[i + 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[]} words | |
| * @return {string[]} | |
| */ | |
| var removeAnagrams = function(words) { | |
| // Helper function to check if two words are anagrams | |
| const isAnagram = (word1, word2) => { | |
| // Sort the letters of both words and compare | |
| return word1.split('').sort().join('') === word2.split('').sort().join(''); | |
| }; |
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} m | |
| * @param {number} k | |
| * @param {number[]} nums | |
| * @return {number} | |
| */ | |
| var magicalSum = function(m, k, nums) { | |
| const MOD = BigInt(1e9 + 7); // Modulo for large number arithmetic | |
| const n = nums.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[]} power | |
| * @return {number} | |
| */ | |
| var maximumTotalDamage = function(power) { | |
| // Step 1: Count how many times each damage value appears | |
| const count = new Map(); | |
| for (const dmg of power) { | |
| count.set(dmg, (count.get(dmg) || 0) + 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 {number[]} energy | |
| * @param {number} k | |
| * @return {number} | |
| */ | |
| var maximumEnergy = function(energy, k) { | |
| // Initialize the answer to a very low number to ensure any valid energy path will be higher | |
| let ans = -1e99; | |
| // Try starting from each index i in the range [0, 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[]} skill | |
| * @param {number[]} mana | |
| * @return {number} | |
| */ | |
| var minTime = function(skill, mana) { | |
| let m = mana.length; // Number of potions | |
| let n = skill.length; // Number of wizards | |
| // done[i] represents the time when wizard i is ready to start the next potion |
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[]} spells | |
| * @param {number[]} potions | |
| * @param {number} success | |
| * @return {number[]} | |
| */ | |
| // Helper function to preprocess potions using a suffix-style bucket sort | |
| var suffixBucketSort = function(potions) { | |
| // Find the maximum potion value to size the result array |
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[]} rains | |
| * @return {number[]} | |
| */ | |
| var avoidFlood = function(rains) { | |
| const n = rains.length; | |
| const ans = new Array(n).fill(1); // default dry days to lake 1 (will be overwritten) | |
| const fullLakes = new Map(); // maps lake number to the day it was last filled | |
| const dryDays = []; // stores indices of dry days |
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 grid representing elevations at each cell. | |
| * @return {number} - Minimum time required to reach bottom-right corner from top-left. | |
| */ | |
| var swimInWater = function (grid) { | |
| const n = grid.length; // Grid is n x n | |
| const dirs = [[1,0],[-1,0],[0,1],[0,-1]]; // Possible movement directions: down, up, right, left | |
| // Custom MinHeap class to prioritize cells with the lowest time (elevation) first | |
| class MinHeap { |
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 matrix of heights, returns coordinates of cells that can flow to both the Pacific and Atlantic oceans. | |
| * Pacific touches the left and top edges; Atlantic touches the right and bottom edges. | |
| * @param {number[][]} heights - 2D grid of elevation values | |
| * @return {number[][]} - List of coordinates [i, j] that can reach both oceans | |
| */ | |
| var pacificAtlantic = function(heights) { | |
| let row = heights.length; | |
| let col = heights[0].length; | |
| let arr = []; // Stores final result: cells that can reach both oceans |