π¨βπ»
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 {boolean} | |
*/ | |
var checkPowersOfThree = function(n) { | |
// Loop until n becomes zero | |
while (n > 0) { | |
// If the remainder when n is divided by 3 is 2, return. false | |
// This means n cannot be represented as the sum of distinct powers of three | |
if (n % 3 === 2) { |
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} pivot | |
* @return {number[]} | |
*/ | |
var pivotArray = function(nums, pivot) { | |
// Arrays to hold elements less than, equal to, and greater than pivot | |
let lessThanPivot = []; | |
let equalToPivot = []; | |
let greaterThanPivot = []; |
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[][]} nums1 | |
* @param {number[][]} nums2 | |
* @return {number[][]} | |
*/ | |
var mergeArrays = function(nums1, nums2) { | |
// Create a set to collect all unique ids | |
let allIds = new Set(); | |
nums1.forEach(num => allIds.add(num[0])); | |
nums2.forEach(num => allIds.add(num[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[][]} nums1 | |
* @param {number[][]} nums2 | |
* @return {number[][]} | |
*/ | |
var mergeArrays = function(nums1, nums2) { | |
// Create a set to collect all unique ids | |
let allIds = new Set(); | |
nums1.forEach(num => allIds.add(num[0])); | |
nums2.forEach(num => allIds.add(num[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 applyOperations = function(nums) { | |
const n = nums.length; | |
// Perform the operations | |
for (let i = 0; i < n - 1; 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} str1 | |
* @param {string} str2 | |
* @return {string} | |
*/ | |
// Function to find the longest common subsequence (LCS) of two strings | |
function findLCS(str1, str2) { | |
const m = str1.length; | |
const n = str2.length; | |
const dp = Array.from({ length: m + 1 }, () => Array(n + 1).fill(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[]} arr | |
* @return {number} | |
*/ | |
var lenLongestFibSubseq = function(arr) { | |
const n = arr.length; | |
if (n < 3) return 0; | |
const indexMap = new Map(); | |
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 {number[]} nums | |
* @return {number} | |
*/ | |
var maxAbsoluteSum = function(nums) { | |
// Initialize variables to store the max sum, current max, min sum, and current min | |
let maxSum = 0; | |
let currentMax = 0; | |
let minSum = 0; | |
let currentMin = 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[]} arr | |
* @return {number} | |
*/ | |
var numOfSubarrays = function(arr) { | |
const MOD = 10**9 + 7; | |
let n = arr.length; | |
let count = 0; | |
let prefixSum = 0; | |
let oddCount = 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[][]} edges | |
* @param {number} bob | |
* @param {number[]} amount | |
* @return {number} | |
*/ | |
var mostProfitablePath = function(edges, bob, amount) { | |
const n = amount.length; | |
const graph = new Map(); |