 Ankit Tiwari 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 …

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 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 …

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 …

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, …

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 …

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 …

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 …

Triangle

Problem Statement Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. Sample Test Cases Problem solution The triangle has a tree-like structure, which would lead people to think about traversal algorithms such as DFS. However, if you look closely, you …

Binary Tree Preorder traversal

Problem Statement Given a binary tree, return the preorder traversal of its nodes’ values. Sample Test Cases Problem Solution We start traversal by pushing the root node into Stack and loop until Stack is empty. In each iteration, you pop the last element from Stack and print its value. That means you visited it. Now, …

Scroll to Top

Full Stack Integrated Bootcamp Free Trial

• Please enter a number from 7000000000 to 9999999999.