Arnab Chakraborty has Published 4293 Articles

Program to find all prime factors of a given number in sorted order in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2020 13:20:24

757 Views

Suppose we have a number n greater than 1, we have to find all of its prime factors and return them in sorted sequence. We can write out a number as a product of prime numbers, they are its prime factors. And the same prime factor may occur more than ... Read More

Program to find minimum total cost for equalizing list elements in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2020 13:15:20

272 Views

Suppose we have two lists of numbers called nums and costs. Now consider, there is an operation where we can increase or decrease nums[i] for cost costs[i]. We can perform any number of these operations, and we want to make all elements equal in the nums. We have to find ... Read More

Program to find a tree by updating values with left and right subtree sum with itself in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2020 13:13:10

279 Views

Suppose we have a binary tree, we have to find the same tree but every node's value is replaced by its its value + all of the sums of its left and right subtrees.So, if the input is likethen the output will beTo solve this, we will follow these steps ... Read More

Program to find the minimum edit distance between two strings in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2020 13:09:22

510 Views

Suppose we have two words S and T, we have to find the minimum number of operations needed to convert from S to T. The operations can be of three types, these areinsert a character, delete a characterreplace a character.So if the input strings are “evaluate” and “fluctuate”, then the ... Read More

Program to count number of unique palindromes we can make using string characters in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2020 12:49:28

282 Views

Suppose we have a string s, we have to find the number of distinct palindromes we can generate using all characters. If the answer is very large then mod the result by 10^9 + 7.So, if the input is like s = "xyzzy", then the output will be 2, as ... Read More

Program to calculate vertex-to-vertex reachablity matrix in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2020 12:46:39

349 Views

Suppose we have a graph as an adjacency list representation, we have to find 2D matrix M whereM[i, j] = 1 when there is a path between vertices i and j.M[i, j] = 0 otherwise.So, if the input is likethen the output will be1111101111011110111101111To solve this, we will follow these ... Read More

Program to count number of ways we can throw n dices in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2020 12:40:00

254 Views

Suppose we have a number n, number of faces, and a total value, we have to find the number of ways it is possible to throw n dice with faces each to get total. If the answer is very large mod the result by 10**9 + 7.So, if the input ... Read More

Program to find sum each of the diagonal path elements in a binary tree in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2020 12:37:45

178 Views

Suppose we have a binary tree, we have to find the sum of each of the diagonals in the tree starting from the top to bottom right.So, if the input is likethen the output will be [27, 18, 3] as the diagonals are [12, 15], [8, 10], [3]. So the ... Read More

Program to sort each diagonal elements in ascending order of a matrix in C++

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2020 12:34:41

523 Views

Suppose we have n x m matrix Mat, we have to sort this Mat diagonally in increasing order from top-left to the bottom right, so that all elements in the diagonals are sorted. So if the input matrix is like −331122121112The output matrix will be −111112221233To solve this, we will ... Read More

Program to find number of moves to win deleting repeated integer game in Python

Arnab Chakraborty

Arnab Chakraborty

Updated on 07-Oct-2020 12:29:47

178 Views

Suppose two friends Amal and Bimal are playing a game with a sorted list of numbers called nums. In this game in a single turn, Amal chooses any three numbers. Bimal removes one of them, and then Amal removes one of them. The list starts out with an odd number ... Read More

Advertisements