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[][]} intervals | |
| * @return {number[]} | |
| */ | |
| var maximumWeight = function(intervals) { | |
| const n = intervals.length; | |
| // augment with original index | |
| let arr = intervals.map((it, i) => ({ l: it[0], r: it[1], w: it[2], idx: 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[]} digits | |
| * @return {number} | |
| */ | |
| var totalNumbers = function(digits) { | |
| // Count how many times each digit appears in the input | |
| const freq = Array(10).fill(0); | |
| for (let d of digits) freq[d]++; | |
| const result = new Set(); // store distinct valid numbers |
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
| /** | |
| * Definition for a binary tree node. | |
| * function TreeNode(val, left, right) { | |
| * this.val = (val===undefined ? 0 : val) | |
| * this.left = (left===undefined ? null : left) | |
| * this.right = (right===undefined ? null : right) | |
| * } | |
| */ | |
| /** | |
| * @param {TreeNode} root |
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 | |
| * @return {number} | |
| */ | |
| var countCommas = function(n) { | |
| // Convert n to BigInt so all math stays consistent | |
| n = BigInt(n); | |
| // Use BigInt for total since we accumulate BigInt values | |
| let total = 0n; |
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 | |
| * @return {number} | |
| */ | |
| var countCommas = function(n) { | |
| // Numbers from 1 to 999 never contain commas in standard formatting. | |
| // Starting at 1000, every number has exactly ONE comma (e.g., "1,000", "4,582"). | |
| // So we simply count how many numbers from 1000 up to n exist. | |
| // If n < 1000, the result should be 0 - hence Math.max(0, n - 999). |
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} s | |
| * @return {number} | |
| */ | |
| var distinctSubseqII = function(s) { | |
| const MOD = 1_000_000_007; | |
| const last = Array(26).fill(0); | |
| let dp = 1; // counts empty subsequence initially |
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} s | |
| * @param {string} t | |
| * @return {number} | |
| */ | |
| var numDistinct = function(s, t) { | |
| const m = s.length, n = t.length; | |
| // dp[j] = number of ways to form t[0..j-1] using processed part of s | |
| const dp = Array(n + 1).fill(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[]} nums | |
| * @param {number} k | |
| * @return {number} | |
| */ | |
| var firstStableIndex = function(nums, k) { | |
| const n = nums.length; | |
| // Build suffix min | |
| const suffMin = Array(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[]} nums | |
| * @param {number} k | |
| * @return {number} | |
| */ | |
| var firstStableIndex = function(nums, k) { | |
| const n = nums.length; | |
| // Build prefix max | |
| const prefixMax = Array(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[]} nums1 | |
| * @return {boolean} | |
| */ | |
| var uniformArray = function(nums1) { | |
| nums1.sort((a, b) => a - b); | |
| let smallestOdd = null; | |
| let smallestEven = null; |
NewerOlder