medium-problems

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 »

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 »

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 »

Find total number of unique paths in a grid with obstacles

Problem Statement A robot is located at the top-left corner of a m x n grid . The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid. Now consider if some obstacles are added to the grids. How many unique paths would there …

Find total number of unique paths in a grid with obstacles Read More »

Find total number of unique paths in a grid

Problem Statement A robot is located at the top-left corner of a m x n grid . The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid. How many possible unique paths are there? Constraints: 1 <= m, n <= 100 It’s guaranteed …

Find total number of unique paths in a grid Read More »

Number of ways to decode a message

Problem Statement A message containing letters from A-Z is being encoded to numbers using the following mapping: Given a non-empty string containing only digits, determine the total number of ways to decode it. Sample Test Cases Problem Solution We will be using Dynamic Programming to solve this problem. Let’s think of the sub problem. To decode a message of …

Number of ways to decode a message Read More »

Scroll to Top

Full Stack Integrated Bootcamp Free Trial

  • Please enter a number from 7000000000 to 9999999999.