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 maximum number of partitions after performing operations | |
* that allow up to `k` distinct characters per partition. | |
* | |
* @param {string} s - Input string consisting of lowercase letters. | |
* @param {number} k - Maximum number of distinct characters allowed per partition. | |
* @return {number} - Maximum number of partitions achievable. | |
*/ | |
var maxPartitionsAfterOperations = function(s, k) { | |
const n = s.length; |
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} value | |
* @return {number} | |
*/ | |
var findSmallestInteger = function(nums, value) { | |
// Step 1: Create a frequency map to count how many times each remainder appears | |
const freq = new Map(); | |
for (let num of nums) { |
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 maxIncreasingSubarrays = function (nums) { | |
let maxK = 0; // Stores the maximum valid k found so far | |
let curLen = 1; // Length of the current strictly increasing run | |
let prevLen = 0; // Length of the previous strictly increasing run | |
for (let i = 1; i < nums.length; 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[]} nums | |
* @param {number} k | |
* @return {boolean} | |
*/ | |
var hasIncreasingSubarrays = function(nums, k) { | |
// Helper function to check if a subarray is strictly increasing | |
function isStrictlyIncreasing(start, end) { | |
for (let i = start; i < end; i++) { | |
if (nums[i] >= nums[i + 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 {string[]} words | |
* @return {string[]} | |
*/ | |
var removeAnagrams = function(words) { | |
// Helper function to check if two words are anagrams | |
const isAnagram = (word1, word2) => { | |
// Sort the letters of both words and compare | |
return word1.split('').sort().join('') === word2.split('').sort().join(''); | |
}; |
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} k | |
* @param {number[]} nums | |
* @return {number} | |
*/ | |
var magicalSum = function(m, k, nums) { | |
const MOD = BigInt(1e9 + 7); // Modulo for large number arithmetic | |
const n = nums.length; |
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[]} power | |
* @return {number} | |
*/ | |
var maximumTotalDamage = function(power) { | |
// Step 1: Count how many times each damage value appears | |
const count = new Map(); | |
for (const dmg of power) { | |
count.set(dmg, (count.get(dmg) || 0) + 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[]} energy | |
* @param {number} k | |
* @return {number} | |
*/ | |
var maximumEnergy = function(energy, k) { | |
// Initialize the answer to a very low number to ensure any valid energy path will be higher | |
let ans = -1e99; | |
// Try starting from each index i in the range [0, 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[]} skill | |
* @param {number[]} mana | |
* @return {number} | |
*/ | |
var minTime = function(skill, mana) { | |
let m = mana.length; // Number of potions | |
let n = skill.length; // Number of wizards | |
// done[i] represents the time when wizard i is ready to start the next potion |
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[]} spells | |
* @param {number[]} potions | |
* @param {number} success | |
* @return {number[]} | |
*/ | |
// Helper function to preprocess potions using a suffix-style bucket sort | |
var suffixBucketSort = function(potions) { | |
// Find the maximum potion value to size the result array |
NewerOlder