π¨βπ»
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 a binary tree node. | |
* function TreeNode(val, left, right) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.left = (left===undefined ? null : left) | |
* this.right = (right===undefined ? null : right) | |
* } | |
*/ | |
/** | |
* @param {number[]} preorder |
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 a binary tree node. | |
* function TreeNode(val, left, right) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.left = (left===undefined ? null : left) | |
* this.right = (right===undefined ? null : right) | |
* } | |
*/ | |
/** | |
* @param {string} traversal |
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 a binary tree node. | |
* function TreeNode(val, left, right) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.left = (left===undefined ? null : left) | |
* this.right = (right===undefined ? null : right) | |
* } | |
*/ | |
/** | |
* @param {TreeNode} root |
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[]} nums | |
* @return {string} | |
*/ | |
var findDifferentBinaryString = function(nums) { | |
const n = nums.length; | |
const numsSet = new Set(nums); | |
// Generate all possible binary strings of length n | |
for (let i = 0; i < 2 ** n; 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} n | |
* @param {number} k | |
* @return {string} | |
*/ | |
var getHappyString = function(n, k) { | |
// Helper function to perform backtracking and generate all happy string | |
function backtrack(current, result) { | |
// If the current string has reached the desired length, add it to the result list | |
if (current.length === 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 {string} pattern | |
* @return {string} | |
*/ | |
var smallestNumber = function(pattern) { | |
const n = pattern.length; | |
const result = []; | |
const stack = []; | |
for (let i = 0; i <= n; 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 {string} tiles | |
* @return {number} | |
*/ | |
var numTilePossibilities = function(tiles) { | |
// Helper function for backtracking | |
function backtrack(path, remaining) { | |
// If the current path is not empty, add it to the set of unique sequences | |
if (path.length > 0) { | |
uniqueSequences.add(path.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} n | |
* @return {number[]} | |
*/ | |
var constructDistancedSequence = function(n) { | |
// Initialize the sequence array with 0s and an array to track placed numbers | |
const seq = new Array(n * 2 - 1).fill(0), isPlaced = new Array(n + 1).fill(false); | |
// Mark index 0 as placed (not used in actual sequence) | |
isPlaced[0] = true; |
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} | |
*/ | |
// Function to check if the string representation of a number can be partitioned | |
// into contiguous substrings that sum to a target value | |
function canPartition(numStr, target) { | |
// Helper function to perform backtracking | |
function backtrack(index, currentSum) { | |
// If we've reached the end of the string, check if the current sum equals the target |
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
var ProductOfNumbers = function() { | |
// Initialize an array to store the prefix products | |
this.prefixProduct = [1]; // Start with 1 to handle the empty product case | |
}; | |
/** | |
* @param {number} num | |
* @return {void} | |
*/ |