π¨βπ»
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) { |
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} x | |
* @param {number} y | |
* @param {number} z | |
* @return {number} | |
*/ | |
var findClosest = function(x, y, z) { | |
// Calculate absolute distance from Person 1 to Person 3 | |
const distance1 = Math.abs(x - z); |
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
/** | |
* Counts the number of valid point pairs (i, j) such that: | |
* - x[i] β€ x[j] | |
* - y[i] β₯ y[j] | |
* - No other point between i and j has the same or higher y[j] | |
* | |
* @param {number[][]} points - Array of [x, y] coordinates | |
* @return {number} - Number of valid pairs | |
*/ | |
var numberOfPairs = function(points) { |
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[][]} points | |
* @return {number} | |
*/ | |
var numberOfPairs = function(points) { | |
let count = 0; | |
// Step 1: Sort points by x ascending, then y descending | |
// This ensures that for any point[i], all point[j] with j < i have x <= x[i] | |
points.sort((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
/** | |
* @param {character[][]} board | |
* @return {void} Do not return anything, modify board in-place instead. | |
*/ | |
var solveSudoku = function(board) { | |
const SIZE = 9; | |
// Track used digits in rows, columns, and 3x3 boxes | |
const row = Array.from({ length: SIZE }, () => Array(SIZE).fill(false)); | |
const col = Array.from({ length: SIZE }, () => Array(SIZE).fill(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
/** | |
* Validates a partially filled 9x9 Sudoku board. | |
* Only filled cells are checked for rule violations. | |
* | |
* @param {character[][]} board - 2D array representing the Sudoku board | |
* @return {boolean} - true if the board is valid, false otherwise | |
*/ | |
var isValidSudoku = function(board) { | |
// Set to track seen digits in rows, columns, and sub-boxes | |
const seen = new Set(); |
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} m | |
* @return {number} | |
*/ | |
var flowerGame = function(n, m) { | |
// Count how many odd numbers are in [1, n] | |
const oddX = Math.floor(n / 2) + (n % 2); // e.g., 1, 3, 5... | |
const evenX = Math.floor(n / 2); // e.g., 2, 4, 6... |
NewerOlder