problem-solution

Minimum Size Subarray Sum

Problem Statement Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn’t one, return 0 instead. Sample Test Cases Problem Solution The better approach to solving the problem is to use two pointers, ptr1 and ptr2, where ptr1 represents the starting index …

Minimum Size Subarray Sum Read More »

Find the Duplicate Number

Problem Statement Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate number, find the duplicate one. Sample Test Case Problem Solution A very simple approach will be to first sort the entire array. If the numbers …

Find the Duplicate Number Read More »

Find the Smallest Divisor Given a Threshold

Video Solution Problem Statement Given an array of integers nums and an integer threshold, we will choose a positive integer divisor and divide all the array by it and sum the result of the division. Find the smallest divisor such that the result mentioned above is less than or equal to threshold. Each result of division is rounded to the nearest integer greater …

Find the Smallest Divisor Given a Threshold Read More »

First Bad Version | Leetcode | Solution

Hi, In this post we will be discussing the first bad version problem present on LeetCode Video Solution Problem Statement 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 …

First Bad Version | Leetcode | Solution Read More »

Total Hamming Distance

Problem Statement The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Now your job is to find the total Hamming distance between all pairs of the given numbers. Sample Test Cases Problem Solution  The fact that all numbers are represented using 32 bits (or some fixed number of …

Total Hamming Distance Read More »

Hamming Distance

Problem Statement The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance. Note:0 ≤ x, y < 231. Sample Test Cases Problem Solution 1)We find XOR of x and y , Why?Because the xor makes the bit to set if the bits bits are different ie, …

Hamming Distance Read More »

Convert Sorted Array To Binary Search Tree

Problem Statement Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. Sample Test Case Problem Solution Since …

Convert Sorted Array To Binary Search Tree Read More »

Counting Inversions In An Array Using Merge Sort

Problem Statement Inversion Count for an array indicates – how far (or close) the array is from being sorted. If array is already sorted then inversion count is 0. If array is sorted in reverse order that inversion count is the maximum. Specifically, if there are two numbers a[i] and a[j] where a[i] > a[j] and …

Counting Inversions In An Array Using Merge Sort Read More »

Sum Root To Leaf Numbers

Problem Statement Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the total sum of all root-to-leaf numbers. Note: A leaf is a node with no children. Sample Test Case Problem Solution 1 / \ 2 3 This is a simple …

Sum Root To Leaf Numbers Read More »

Scroll to Top

Full Stack Integrated Bootcamp Free Trial

  • Please enter a number from 7000000000 to 9999999999.