Find the Largest Cube by Deleting Minimum Digits from a Number in Python

Arnab Chakraborty
Updated on 27-Aug-2020 12:59:58

163 Views

Suppose we have a number N, we have to determine the largest perfect cube that can be generated by removing minimum digits (possibly 0) from the number. We can delete any digit from the given number to reach the target. As we know a number N is called a perfect cube if N = M^3 for some integer M.So, if the input is like 806, then the output will be 8, as we can delete 0 and 6 from the number, then we will get 8, this is perfect cube of 2.To solve this, we will follow these steps −Define ... Read More

Find the Largest Complete Subtree in a Given Binary Tree in Python

Arnab Chakraborty
Updated on 27-Aug-2020 12:56:20

297 Views

Suppose we have a Binary Tree; we have to find the size of maximum complete sub-tree in this Binary Tree. As we know a complete binary tree is a Binary Tree if all levels are completely filled without possibly the final level and the final level has all keys as left as possible.So, if the input is likethen the output will be 4 as size and inorder traversal will be 10, 45, 60, 70, To solve this, we will follow these steps −Define return type with few parameters like isComplete, isPerfect, these are initially false, then size and rootTree, size ... Read More

Find Pair with Maximum NCR Value in Python

Arnab Chakraborty
Updated on 27-Aug-2020 12:50:19

193 Views

Suppose we have an array arr with n integers, we have to find arr[i] and arr[j] from the array such that arr[i]Carr[j] is at large as possible. If there is more than one pair, return any one of them.So, if the input is like [4, 1, 2], then the output will be 4 2 as 4C1 = 4, 4C2 = 6 and 2C1 = 2, so (4, 2) is only pair as we want.To solve this, we will follow these steps −sort the list vN := v[n - 1]if N mod 2 is same as 1, thenfirst := N / ... Read More

Minimum Removals from Array to Make GCD Greater in Python

Arnab Chakraborty
Updated on 27-Aug-2020 12:45:31

205 Views

Suppose we have a list of N numbers; we have to find the minimum number of removal of numbers are required so that the GCD of the remaining numbers is larger than initial GCD of N numbers.So, if the input is like [6, 9, 15, 30], then the output will be 2 as the initial gcd is 3, so after removing 6 and 9 we can get gcd as 15, 15 > 3.To solve this, we will follow these steps −INF := 100001spf := a list with elements 0 to INFDefine a function sieve()for i in range 4 to INF, ... Read More

Virtual Function Called Inside Non-Virtual Function in C++

Arnab Chakraborty
Updated on 27-Aug-2020 12:43:40

317 Views

In this section we will discuss about interesting facts about virtual classes in C++. We will see two cases first, then we will analyze the fact.At first execute the program without using any virtual function.The execute the program using any virtual function under non-virtual function.ExampleLet us see the following implementation to get better understanding − Live Demo#include using namespace std; class BaseClass { public:    void display(){       cout

Find Three Elements from Different Arrays for Sum in Python

Arnab Chakraborty
Updated on 27-Aug-2020 12:41:39

212 Views

Suppose we have three arrays A, B, C and another value called "sum", We have to check whether there are three elements a, b, c such that a + b + c = sum and a, b and c should be under three different arrays.So, if the input is like A = [2, 3, 4, 5, 6], B = [3, 4, 7, 2, 3], C = [4, 3, 5, 6, 7], sum = 12, then the output will be True as 4+2+6 = 12, and 4, 2, 6 are taken from A, B, C respectively.To solve this, we will follow ... Read More

Minimum Edges Required to Make Euler Circuit in Python

Arnab Chakraborty
Updated on 27-Aug-2020 12:40:55

183 Views

Suppose we have an undirected graph of b number of nodes and a number of edges; we have to find minimum edges needed to build Euler Circuit in this graph.So, if the input is likethen the output will be 1.To solve this, we will follow these steps −Define a function dfs() . This will take g, visit, odd_vert, degree, comp, vvisit[v] := 1if degree[v] mod 2 is same as 1, thenodd_vert[comp] := odd_vert[comp] + 1for u in range 0 to size of g[v], doif visit[u] is same as 0, thendfs(g, visit, odd_vert, degree, comp, u)From the main method do the ... Read More

Find the Winner of a Game with Binary String Scores in Python

Arnab Chakraborty
Updated on 27-Aug-2020 12:40:25

252 Views

Suppose we have one binary string representing the scores of a volleyball match, we have to find the winner of the match based on following conditions −There are two teams play with each other and the team which scores 15 points first will be the winner except when both teams have reached to 14 points.When both teams have reached 14 points at that time the team maintaining a lead of two points will be the winner.From the given binary string, the 0 is representing team lose a point and 1 indicates team win a point. We have to check whether ... Read More

Find the Winner by Adding Pairwise Difference in Python

Arnab Chakraborty
Updated on 27-Aug-2020 12:36:39

152 Views

Suppose we have an array A of positive integers, the elements are unique, now, two players P and Q are playing a game. At each move, any one player picks two numbers a and b from the array and if |a – b| is not in the array after that the player adds this number to the array. When a player cannot make the move loses the game. We have to find the winner of the game if player P always starts the game.So, if the input is like A = [8, 9, 10], then the output will be P.To ... Read More

Minimum Cuts in a Chessboard in Python

Arnab Chakraborty
Updated on 27-Aug-2020 12:36:12

98 Views

Suppose we have one A x B chessboard (matrix), we have to calculate the maximum numbers of cuts that we can make in this board so that the board is not divided into 2 parts.So, if the input is like A = 2 and B = 4, then the output will be 3To solve this, we will follow these steps −res := 0res :=(M - 1) *(N - 1)return resExampleLet us see the following implementation to get better understanding − Live Demodef max_cuts_count(M, N):    res = 0    res = (M - 1) * (N - 1)    return res ... Read More

Advertisements