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[]} wordlist | |
* @param {string[]} queries | |
* @return {string[]} | |
*/ | |
var spellchecker = function(wordlist, queries) { | |
// Helper function to normalize vowels in a word | |
const normalizeVowels = (word) => { | |
return word.toLowerCase().replace(/[aeiou]/g, '*'); | |
}; |
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 maxFreqSum = function(s) { | |
// Step 1: Define vowels for easy lookup | |
const vowels = new Set(['a', 'e', 'i', 'o', 'u']); | |
// Step 2: Create frequency maps for vowels and consonants | |
const vowelFreq = {}; |
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 {boolean} | |
*/ | |
var doesAliceWin = function(s) { | |
// Define a set containing all lowercase English vowels | |
const vowels = new Set(['a', 'e', 'i', 'o', 'u']); | |
let prefixParity = new Set(); | |
// Initialize a counter to track the number of vowels in the string | |
let count = 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
/** | |
* Sorts all vowels in the input string in non-decreasing order, | |
* while keeping consonants and other characters in their original positions. | |
* | |
* @param {string} s - The input string to process. | |
* @return {string} - The resulting string with sorted vowels. | |
*/ | |
const sortVowels = function(s) { | |
const vowels = new Set(['a', 'e', 'i', 'o', 'u', '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} n | |
* @param {number[][]} languages | |
* @param {number[][]} friendships | |
* @return {number} | |
*/ | |
var minimumTeachings = function(n, languages, friendships) { | |
// 1) Convert each user's language list to a Set for 0(1) checks. | |
// We'll store with 1-based alignment: user i => index i (ignore index 0). | |
const userLangs = Array(languages.length + 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 | |
* @param {number} delay | |
* @param {number} forget | |
* @return {number} | |
*/ | |
var peopleAwareOfSecret = function(n, delay, forget) { | |
const MOD = 1e9 + 7; | |
// dp[i] = number of people who learn the secret on day 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
/** | |
* Helper function to check if a number is a No-Zero integer | |
* A No-Zero integer has no '0' digit in its decimal representation | |
*/ | |
function isNoZero(num) { | |
return !num.toString().includes('0'); | |
}; | |
/** | |
* Main function to find two No-Zero integers that sum to 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} n | |
* @return {number[]} | |
*/ | |
var sumZero = function(n) { | |
const result = []; | |
// Add symmetric pairs: [-1, 1], [-2, 2], ... | |
for (let i = 1; i <= Math.floor(n / 2); i++) { | |
result.push(-i, 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
/** | |
* Calculates the minimum number of operations required to reduce | |
* all elements in each query range [l, r] to zero. | |
* | |
* In one operation, select two numbers and replace them with floor(a / 4) and floor(b / 4). | |
* | |
* This solution groups numbers by their "division depth" — how many times | |
* they must be divided by 4 before reaching 0 — and counts how many numbers | |
* fall into each depth level. | |
* |
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
/** | |
* Determines the minimum number of operations needed to reduce num1 to 0. | |
* Each operation subtracts (2^i + num2), where i ∈ [0, 60]. | |
* Returns -1 if it's impossible. | |
* | |
* @param {number} num1 - Starting value | |
* @param {number} num2 - Fixed offset added to each power of 2 | |
* @return {number} - Minimum number of operations or -1 | |
*/ | |
var makeTheIntegerZero = function(num1, num2) { |