Overview An ugly number is a number whose prime factors are limited to 2,3 and 5. We have already seen a program where given a number n returns true if it is…
Author: admin
Program for an ugly number
Overview An ugly number is a number whose prime factors are limited to 2,3 and 5. Given a number, n return true if it is an ugly number otherwise return false. Example…
Is Graph Bipartite Program
Overview An undirected graph is given. A graph is said to be bipartite if the nodes of the graph can be partitioned into two subsets such that every edge connects one node…
Binary Tree Maximum Path Sum Program
Overview A binary tree is given. The objective is to find the maximum Path Sum in that binary tree. A path in a binary tree is a sequence of nodes that are connected…
Sort characters by frequency
Overview An input string is given. The objective is to sort the string based on frequency. We have to sort based on decreasing order of the frequency of characters. Let’s understand it…
Program for Income Tax Paid
Overview A 2d array is given which represents the bracket of income tax. The input array is brackets where which means that ith bracket has an upper bound of upperi and is…
Check If N and Its Double Exist
Overview An array is given. The objective is to find if there exists any number for which it’s double also exists. Example 1 Example 2 The idea is to use a map…
Program for Pascal’s Triangle
Overview The objective is to find the print n number of rows of Pascal’s triangle. The number n is given as an input to the program Example 1 Example 2 Refer to…
Longest Consecutive Sequence Program
Overview An integer array is given. Find the length of the longest consecutive sequence in it. Let’s see an example to understand it Example 1 Example 2 The naive idea is to…
Print all Binary Tree Paths
Overview The root of a tree is given. The objective is to print all the tree paths starting with the root. Example Output: Program Below is the program for the same Output:…