Guess Number Higher or Lower in JavaScript (Leetcode Problem)

0 We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess. You call a pre-defined API int guess(int num), which returns … Read more

Find  First Bad Version in JavaScript (Leetcode Problem)

0 Problem You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad. Suppose you have n versions [1, 2, …, n] and you … Read more

Search Insert Position in JavaScript (Leetcode problem)

0 Problem Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n) runtime complexity. Example 1: Input: nums = [1,3,5,6], target = 5 Output: 2 Example … Read more

Binary tree postorder traversal in JavaScript

0 Problem Given the root of a binary tree, return the postorder traversal of its nodes’ values. Example 1: Input: root = [1,null,2,3] Output: [3,2,1] Solution Aadi AhlawatA freelance web developer with a decade of experience in creating high-quality, scalable web solutions. His expertise spans PHP, WordPress, Node.js, MySQL, MongoDB, and e-commerce development, ensuring a versatile approach to each … Read more

Binary tree preorder traversal in JavaScript

0 Problem Given the root of a binary tree, return the preorder traversal of its nodes’ values. Example 1: Input: root = [1,null,2,3] Output: [1,2,3] Solution Aadi AhlawatA freelance web developer with a decade of experience in creating high-quality, scalable web solutions. His expertise spans PHP, WordPress, Node.js, MySQL, MongoDB, and e-commerce development, ensuring a versatile approach to … Read more

Binary tree in order traversal in JavaScriptc

0 Problem Given the root of a binary tree, return the inorder traversal of its nodes’ values. Example 1: Input: root = [1,null,2,3] Output: [1,3,2] Solution Aadi AhlawatA freelance web developer with a decade of experience in creating high-quality, scalable web solutions. His expertise spans PHP, WordPress, Node.js, MySQL, MongoDB, and e-commerce development, ensuring a versatile approach to … Read more

Find running sum of an array in JavaScript

0 Problem Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]). Return the running sum of nums. Solution Aadi AhlawatA freelance web developer with a decade of experience in creating high-quality, scalable web solutions. His expertise spans PHP, WordPress, Node.js, MySQL, MongoDB, and e-commerce development, ensuring a versatile approach to each … Read more

Find pivot index of an array in JavaScript

0 Problem statement Given an array of integers nums, calculate the pivot index of this array. The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index’s right. If the index is on the left edge of the array, then the left … Read more

Skip to content