π¨βπ»
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
/** | |
* Checks if the array can be made zero with a given number of queries. | |
* @param {number[]} nums - The array of numbers. | |
* @param {number[][]} queries - The array of queries. | |
* @param {number} limit - The number of queries to use. | |
* @return {boolean} - Returns true if the array can be made zero, false otherwise. | |
*/ | |
let check = (nums, queries, limit) => { | |
let arr = new Array(nums.length + 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 | |
* @return {number} | |
*/ | |
var maximumCount = function(nums) { | |
// Initialize counters for positive and negative integers | |
let posCount = 0; | |
let negCount = 0; | |
// Iterate through the 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 {string} s - Input string containing characters 'a', 'b', and 'c' | |
* @return {number} - Number of substrings containing at least one 'a', 'b', and 'c' | |
*/ | |
var numberOfSubstrings = function(s) { | |
let count = 0; // To keep track of the number of unique characters 'a', 'b', and 'c' in the current window | |
let map = {'a': 0, 'b': 0, 'c': 0}; // Map to store the count of each character 'a', 'b', and 'c' | |
let res = 0; // To store the result (number of substrings) | |
let l = 0; // Left pointer for the sliding window |
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} word | |
* @param {number} k | |
* @return {number} | |
*/ | |
var countOfSubstrings = function(word, k) { | |
// Function to count substrings with at least k consonants | |
function atLeastK(word, k) { | |
const vowels = new Set(['a', 'e', 'i', 'o', 'u']); |
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[]} colors | |
* @param {number} k | |
* @return {number} | |
*/ | |
var numberOfAlternatingGroups = function(colors, k) { | |
// Extend the colors array to handle the circular nature by appending the first (k - 1) elements to the end | |
colors.push(...colors.slice(0, k - 1)); | |
let count = 0; // Counter for the number of alternating 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} blocks | |
* @param {number} k | |
* @return {number} | |
*/ | |
var minimumRecolors = function(blocks, k) { | |
const n = blocks.length; | |
let whiteBlocks = 0; | |
// Initialize the count of white blocks in the first window of length 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} left | |
* @param {number} right | |
* @return {number[]} | |
*/ | |
// Function to check if a number is prime | |
function isPrime(num) { | |
if (num <= 1) return false; | |
if (num <= 3) return true; | |
if (num % 2 === 0 || num % 3 === 0) return false; |
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 findMissingAndRepeatedValues = function(grid) { | |
const n = grid.length; | |
const expectedSum = (n * n * (n * n + 1)) / 2; | |
let actualSum = 0; | |
const numCounts = {}; | |
let repeating = -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} n | |
* @return {number} | |
*/ | |
var coloredCells = function(n) { | |
// This function calculates the number of blue cells in the grid after 'n' minutes. | |
// The formula is derived as the sum of two squares: | |
// (n * n) represents the number of cells in an n x n grid, which is the inner square. | |
// ((n - 1) * (n - 1)) represents the number of cells in an (n-1) x (n-1) grid, which is the outer ring. | |
return (n * n) + ((n - 1) * (n - 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} n | |
* @return {boolean} | |
*/ | |
var checkPowersOfThree = function(n) { | |
// Loop until n becomes zero | |
while (n > 0) { | |
// If the remainder when n is divided by 3 is 2, return. false | |
// This means n cannot be represented as the sum of distinct powers of three | |
if (n % 3 === 2) { |