π¨βπ»
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[][]} queries | |
* @return {boolean} | |
*/ | |
var isZeroArray = function(nums, queries) { | |
// Create a difference array initialized with zeros | |
let diff = new Array(nums.length + 1).fill(0); | |
// Apply range updates using the difference 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[]} nums | |
* @param {number[][]} queries | |
* @return {boolean} | |
*/ | |
var isZeroArray = function(nums, queries) { | |
// Create a difference array initialized with zeros | |
let diff = new Array(nums.length + 1).fill(0); | |
// Apply range updates using the difference 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[]} nums | |
* @return {string} | |
*/ | |
var triangleType = function(nums) { | |
// Check if the input array has exactly 3 sides | |
if (nums.length !== 3) { | |
return "none"; | |
} |
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 | |
* @return {number} | |
*/ | |
var colorTheGrid = function(m, n) { | |
const MOD = 10**9 + 7; | |
let validRows = new Map(); // Store valid row configurations and their count | |
// Generate all possible valid row colorings (using backtracking) |
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
/** | |
* Finds the longest subsequence of words where each word is | |
* "compatible" with the next and belongs to different groups. | |
* | |
* @param {string[]} words - Array of words. | |
* @param {number[]} groups - Corresponding group identifiers. | |
* @return {string[]} - Longest subsequence satisfying the constraints. | |
*/ | |
var getWordsInLongestSubsequence = function(words, groups) { | |
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 | |
* @param {number[]} groups | |
* @return {string[]} | |
*/ | |
var getLongestSubsequence = function(words, groups) { | |
if (!words.length) return []; // If words array is empty, return an empty array | |
let result = [words[0]]; // Start with the first word in the sequence | |
let prevGroup = groups[0]; // Track the previous group value |
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
/** | |
* Computes the length of the transformed string after t transformations. | |
* @param {string} s - Input string consisting of lowercase English letters. | |
* @param {number} t - Number of transformations to apply. | |
* @param {number[]} nums - Array of size 26, mapping each letter to its transformation size. | |
* @returns {number} - Length of the resulting string modulo 10^9 + 7. | |
*/ | |
function lengthAfterTransformations(s, t, nums) { | |
const MOD = 1000000007n; // Large prime number for modulo operations | |
const bigT = BigInt(t); // Convert `t` to BigInt to handle large values |
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 {number} t | |
* @return {number} | |
*/ | |
var lengthAfterTransformations = function(s, t) { | |
const MOD = 1000000007; | |
const n = s.length; | |
// Step 1: Count occurrences of each character in 's' |
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
/** | |
* Finds all three-digit even numbers that can be formed using the given digits. | |
* @param {number[]} digits - An array of digits (0-9). | |
* @return {number[]} - An array of unique three-digit even numbers. | |
*/ | |
var findEvenNumbers = function(digits) { | |
const arr = []; // Stores valid even numbers | |
const ct = Array(10).fill(0); // Count occurrences of each digit (0-9) | |
// Count frequency of digits in the input 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
/** | |
* Function to determine the maximum possible sum by replacing zeros | |
* in either of the given arrays. | |
* | |
* @param {number[]} nums1 - First array of numbers | |
* @param {number[]} nums2 - Second array of numbers | |
* @return {number} - Maximum possible sum or -1 if impossible | |
*/ | |
var minSum = function(nums1, nums2) { | |
let zeroCount1 = 0; // Count of zeros in nums1 |