Skip to content

Instantly share code, notes, and snippets.

View tatsuyax25's full-sized avatar
πŸ‘¨β€πŸ’»
Focusing

Miguel Urena tatsuyax25

πŸ‘¨β€πŸ’»
Focusing
View GitHub Profile
@tatsuyax25
tatsuyax25 / isZeroArray.js
Last active June 2, 2025 16:20
You are given an integer array nums of length n and a 2D array queries, where queries[i] = [li, ri]. For each queries[i]: Select a subset of indices within the range [li, ri] in nums. Decrement the values at the selected indices by 1. A Zero Array
/**
* @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
@tatsuyax25
tatsuyax25 / isZeroArray.js
Created May 20, 2025 19:12
You are given an integer array nums of length n and a 2D array queries, where queries[i] = [li, ri]. For each queries[i]: Select a subset of indices within the range [li, ri] in nums. Decrement the values at the selected indices by 1. A Zero Array
/**
* @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
@tatsuyax25
tatsuyax25 / triangleType.js
Created May 19, 2025 16:46
You are given a 0-indexed integer array nums of size 3 which can form the sides of a triangle. A triangle is called equilateral if it has all sides of equal length. A triangle is called isosceles if it has exactly two sides of equal length. A triang
/**
* @param {number[]} nums
* @return {string}
*/
var triangleType = function(nums) {
// Check if the input array has exactly 3 sides
if (nums.length !== 3) {
return "none";
}
@tatsuyax25
tatsuyax25 / colorTheGrid.js
Created May 18, 2025 16:48
You are given two integers m and n. Consider an m x n grid where each cell is initially white. You can paint each cell red, green, or blue. All cells must be painted. Return the number of ways to color the grid with no two adjacent cells having the
/**
* @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)
@tatsuyax25
tatsuyax25 / getWordsInLongestSubsequence.js
Created May 16, 2025 20:41
You are given a string array words, and an array groups, both arrays having length n. The hamming distance between two strings of equal length is the number of positions at which the corresponding characters are different. You need to select the lo
/**
* 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) {
@tatsuyax25
tatsuyax25 / getLongestSubsequence.js
Created May 15, 2025 17:03
You are given a string array words and a binary array groups both of length n, where words[i] is associated with groups[i]. Your task is to select the longest alternating subsequence from words. A subsequence of words is alternating if for any two c
/**
* @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
@tatsuyax25
tatsuyax25 / lengthAfterTransformations.js
Created May 14, 2025 16:30
You are given a string s consisting of lowercase English letters, an integer t representing the number of transformations to perform, and an array nums of size 26. In one transformation, every character in s is replaced according to the following rul
/**
* 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
@tatsuyax25
tatsuyax25 / lengthAfterTransformations.js
Created May 13, 2025 17:11
You are given a string s and an integer t, representing the number of transformations to perform. In one transformation, every character in s is replaced according to the following rules: If the character is 'z', replace it with the string "ab". Oth
/**
* @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'
@tatsuyax25
tatsuyax25 / findEvenNumbers.js
Created May 12, 2025 15:58
You are given an integer array digits, where each element is a digit. The array may contain duplicates. You need to find all the unique integers that follow the given requirements: The integer consists of the concatenation of three elements from di
/**
* 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
@tatsuyax25
tatsuyax25 / minSum.js
Created May 10, 2025 17:32
You are given two arrays nums1 and nums2 consisting of positive integers. You have to replace all the 0's in both arrays with strictly positive integers such that the sum of elements of both arrays becomes equal. Return the minimum equal sum you ca
/**
* 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