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 {number} | |
| */ | |
| var minimumDifference = function(nums, k) { | |
| // If k is 1, picking a single student always gives difference = 0 | |
| if (k === 1) return 0; | |
| // Sort scores so close values sit next to each other |
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 | |
| * @return {number} | |
| */ | |
| var minPairSum = function(nums) { | |
| // Step 1: Sort the array so we can pair smallest with largest | |
| nums.sort((a, b) => a - b); | |
| let left = 0; // pointer to smallest element | |
| let right = nums.length - 1; // pointer largest element |
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
| /** | |
| * Simulates the "minimum adjacent sum merge" process efficiently using: | |
| * - A doubly linked list (prev/next) to track alive indices | |
| * - Versioning (ver[]) to invalidate stale heap entries | |
| * - A custom typed min‑heap for fast pair selection | |
| * - An inversion counter to detect when the array becomes non‑decreasing | |
| * | |
| * @param {number[]} nums | |
| * @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[]} nums | |
| * @return {number[]} | |
| */ | |
| var minBitwiseArray = function(nums) { | |
| const ans = new Array(nums.length); | |
| for (let i = 0; i < nums.length; i++) { | |
| const p = nums[i]; |
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 | |
| * @return {number[]} | |
| */ | |
| var minBitwiseArray = function(nums) { | |
| const ans = new Array(nums.length); | |
| for (let i = 0; i < nums.length; i++) { | |
| const p = nums[i]; |
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[][]} mat | |
| * @param {number} threshold | |
| * @return {number} | |
| */ | |
| var maxSideLength = function(mat, threshold) { | |
| const m = mat.length; | |
| const n = mat[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[][]} grid | |
| * @return {number} | |
| */ | |
| var largestMagicSquare = function(grid) { | |
| const m = grid.length; | |
| const n = grid[0].length; | |
| // Helper: check if the k×k square starting at (r, c) is magic | |
| function isMagic(r, c, 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[][]} bottomLeft | |
| * @param {number[][]} topRight | |
| * @return {number} | |
| */ | |
| var largestSquareArea = function(bottomLeft, topRight) { | |
| let n = bottomLeft.length; | |
| let maxArea = 0; | |
| // Compare every pair of rectangles (i, j) |
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} n | |
| * @param {number[]} hFences | |
| * @param {number[]} vFences | |
| * @return {number} | |
| */ | |
| var maximizeSquareArea = function(m, n, hFences, vFences) { | |
| const MOD = 1_000_000_007; |
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} m | |
| * @param {number[]} hBars | |
| * @param {number[]} vBars | |
| * @return {number} | |
| */ | |
| var maximizeSquareHoleArea = function(n, m, hBars, vBars) { | |
| /** | |
| * Finds the longest run of consecutive integers in an array. |
NewerOlder