π¨βπ»
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 maximumUniqueSubarray = function(nums) { | |
let seen = new Set(); // To track unique elements in the current window | |
let left = 0; // Left boundary of the sliding window | |
let maxScore = 0; // To Keep track of the maximum score found | |
let currentSum = 0; // Sum of the current 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[][]} paths | |
* @return {string[][]} | |
*/ | |
// Trie node definition to build the folder structure | |
function TrieNode() { | |
this.next = new Map(); // maps folder name to child TrieNode | |
this.marked = false; // flag for duplicate detection | |
} |
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 - Array containing 3n integers | |
* @return {number} - Minimum difference between two parts after removing n elements | |
*/ | |
var minimumDifference = function(nums) { | |
const n = nums.length / 3; | |
// Max heap for prefix sums (we want the smallest n elements for left side) | |
let maxHeap = []; | |
let leftSum = 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 | |
* @param {number} k | |
* @return {number} | |
*/ | |
var maximumLength = function(nums, k) { | |
const n = nums.length; | |
// dp[i][mod] = max length of valid subsequence ending at index i with mod class `mod` | |
const dp = Array.from({ length: n }, () => new Map()); | |
let maxLength = 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 maximumLength = function(nums) { | |
const n = nums.length; | |
// Counters for how many times each "type" of parity combo appears | |
let oddodd = 0; // odd element followed by odd sum? (Not well defined here) | |
let eveneven = 0; // even element followed by even sum? |
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 | |
* @return {boolean} | |
*/ | |
var isValid = function(word) { | |
// β Check if the word has at least 3 characters | |
if (word.length < 3) return false; | |
// β Check if the word contains only English letters and digits | |
// This regular expression ensures all characters are alphanumeric |
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
/** | |
* Definition for singly-linked list. | |
* function ListNode(val, next) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.next = (next===undefined ? null : next) | |
* } | |
*/ | |
/** | |
* @param {ListNode} head | |
* @return {number} |
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[]} players | |
* @param {number[]} trainers | |
* @return {number} | |
*/ | |
var matchPlayersAndTrainers = function(players, trainers) { | |
// Step 1: Sort both arrays | |
players.sort((a, b) => a - b); | |
trainers.sort((a, b) => a - b); |
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 earliest and latest round two top players can meet in a knockout tournament. | |
* @param {number} n - Total number of players. | |
* @param {number} firstPlayer - The position of one top player. | |
* @param {number} secondPlayer - The position of the other top player. | |
* @return {number[]} - [earliestRound, latestRound] | |
*/ | |
var earliestAndLatest = function(n, firstPlayer, secondPlayer) { | |
// Normalize player positions: ensure lower < upper | |
let lower = Math.min(firstPlayer, secondPlayer); |
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[][]} meetings | |
* @return {number} | |
*/ | |
var mostBooked = function(n, meetings) { | |
// Initialize arrays to track the number of bookings and the end times of the last meetings for each room | |
const count = new Array(n).fill(0); | |
const roomEndTimes = new Array(n).fill(0); |
NewerOlder