Arnab Chakraborty has Published 4293 Articles

Perfect Squares in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 09:08:12

533 Views

Suppose we have a positive integer n, find the least number of perfect square numbers whose sum is n. So if the number is 13, then the output is 2, as the numbers are 13 = 9 + 4To solve this, we will follow these steps −create one table for ... Read More

Search a 2D Matrix II in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 09:07:25

637 Views

   Suppose we have one m x n matrix. We have to write an efficient algorithm that searches for a value in that matrix. This matrix has the following properties −Integers in each row are sorted in ascending from left to right.Integers in each column are sorted in ascending from ... Read More

Product of Array Except Self in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 09:06:39

1K+ Views

Suppose we have an array called nums of n integers where n > 1. We have to find an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. So if the input array is [1, 2, 3, 4], then the output ... Read More

Lowest Common Ancestor of a Binary Tree in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 09:05:27

1K+ Views

Suppose we have a binary tree. we have to find the Lowest common ancestor nodes of two given nodes. The LCA of two nodes p and q is actually as the lowest node in tree that has both p and q as decedent. So if the binary tree is like ... Read More

Kth Smallest Element in a BST in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 09:03:32

1K+ Views

Suppose we have a binary search tree. We have to find the Kth smallest element in that BST. So if the tree is like −So if we want to find 3rd smallest element, then k = 3, and result will be 7.To solve this, we will follow these steps −create ... Read More

Count Complete Tree Nodes in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 09:02:45

921 Views

Suppose we have a complete binary tree, we have to count the number of nodes. So if the tree is like −So the output will be 6.To solve this, we will follow these stepsThis will use the recursive approach. This method, countNodes() is taking the root as argument.hr := 0 ... Read More

Combination Sum IIII in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 09:01:23

176 Views

Consider we have to generate all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used. Each combination should be a unique set of numbers. All numbers should be positive, and the solution must not contain duplicate ... Read More

Kth Largest Element in an Array in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 09:00:26

2K+ Views

Suppose we have an unsorted array, we have to find the kth largest element from that array. So if the array is [3, 2, 1, 5, 6, 4] and k = 2, then the result will be 5.To solve this, we will follow these steps −We will sort the element, ... Read More

House Robber II in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 08:59:30

781 Views

Consider, you are a professional robber. And you are planning to rob houses along a street. Each house has a certain amount of money stored. All houses are arranged in a circle. That means the first house is the neighbor of the last house. We have to keep in mind ... Read More

Implement Trie (Prefix Tree) in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 04-May-2020 08:58:35

5K+ Views

Suppose we have to make the trie structure, with three basic operations like insert(), search(), startsWith() methods. We can assume that all inputs are in lowercase letters. For example, if we call the functions as follows, we will see the outputsTrie trie = new Trie()trie.insert(“apple”)trie.search(“apple”)     //This will return truetrie.search(“app”)  ... Read More

Advertisements