Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 111 of 377

Find the Largest Cube formed by Deleting minimum Digits from a number in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 241 Views

ConceptWith respect of given number N, our task is to determine the largest perfect cube that can be formed by deleting minimum digits (possibly 0) from the number. So any digit can be deleted from the given number to reach the target.A is called a perfect cube if A = B^3 for some integer B.It has been seen that If the number cannot be perfect cube print -1.ExampleLet N = 1025. It has been seen that if we delete 0 from the above number we will get 125 as remaining number, which is cube root of 5(5 * 5 * ...

Read More

Check for balanced parentheses in an expression - O(1) space - O(N^2) time complexity in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 529 Views

ConceptWith respect of given a string str containing characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, the task is to find if brackets are balanced or not.Brackets are denoted as balanced if −We close open brackets must be closed by the same type of brackets.Again we close open brackets according to the correct order.Input − str = “(()){}”Output − YesInput − str = “))(([][”Output − NoMethodAssign two variables a and b to keep track of two brackets to be compared.A count should be maintained whose value increments on encountering opening bracket and decrements on encountering a closing bracket.Assign b = ...

Read More

Check if a given Binary Tree is height balanced like a Red-Black Tree in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 298 Views

ConceptWith respect of a Red-Black Tree, the largest height of a node is at most double the minimum height.For a given Binary Search Tree, we need to verify for following property.With respect of every node, length of the longest leaf to node path has not more than double the nodes on shortest path from node to leaf.Examples13    41 \    / \ 15  11 101 \   /    \ 17 61 151Above tree cannot be a Red-Black Tree Above tree can be Red-Black Tree with any color assignmentMax height of 13 is 1Min height of 13 is 3  ...

Read More

Check if a given Binary Tree is Heap in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 468 Views

ConceptWith respect of a given binary tree, we need to verify whether it has heap property or not, Binary tree need to satisfy the following two conditions for being a heap –Binary tree should be a complete tree (i.e. all levels except last should be full).Binary tree's every node’s value should be greater than or equal to its child node (considering max-heap).ExampleWith respect of following example this tree contains heap property –The following example does not have heap property –MethodIt is required to verify each of the above condition separately, for verifying completeness isComplete(This function checks if the binary tree ...

Read More

Check if a given string is a valid number in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 590 Views

ConceptIt should be validated if a given string is numeric.Input − str = "12.5"Output − trueInput − str = "def"Output − falseInput − str = "2e5"Output − trueInput − 10e4.4Output − falseMethodWe have to handle the following cases in the code.We have to ignore the leading and trailing white spaces.We have to ignore the ‘+’, ‘-‘ and’.’ at the start.We have to ensure that the characters in the string belong to {+, -, ., e, [0-9]}We have to ensure that no ‘.’ comes after ‘e’.A digit should follow a dot character ‘.’.We have to ensure that the character ‘e’ should ...

Read More

Check if a key is present in every segment of size k in an array in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 494 Views

ConceptWith respect of a given array arr1[] with size of array N, one another key X and a segment size K, the task is to determine that the key X present in every segment of size K in arr1[].Input arr1[] = { 4, 6, 3, 5, 10, 4, 2, 8, 4, 12, 13, 4} X = 4 K = 3Output YesThere are existence of 4 non-overlapping segments of size K in the array, {4, 6, 3}, {5, 10, 4}, {2, 8, 4} and {12, 13, 4}. 4 is present all segments.Input arr1[] = { 22, 24, 57, 66, 35, 55, 77, 33, 24, ...

Read More

Check if a king can move a valid move or not when N nights are there in a modified chessboard in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 459 Views

ConceptWith respect of given infinite chessboard with the same rules as that of chess and given N knights coordinates on the infinite chessboard (-10^9 {3, 4}Output NoThe king can be able to make valid moves.MethodHere, the knight’s move is unusual among chess pieces. Its movement is towards a square that is two squares away horizontally and one square vertically, or two squares vertically and one square horizontally. So, the complete move looks like the letter “L” in every shape possible (8 possible moves). As a result of this, apply a hash map of pairs to mark all possible coordinates where ...

Read More

Check if a line at 45 degree can divide the plane into two equal weight parts in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 189 Views

Suppose we have n different points (Xi, Yi) in 2D coordinate and each point has a weight Wi, we have to check whether a line at 45 degree can be drawn. So that the sum of weights of points on each side will be same.So, if the input is like[[-1, 1, 3], [-2, 1, 1], [1, -1, 4]], then the output will be True/To solve this, we will follow these steps −n := size of vDefine one map weight_at_xmax_x := -2000, min_x := 2000for initialize i := 0, when i < n, update (increase i by 1), do −temp_x := ...

Read More

Check if a number is a Trojan Numbers in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 186 Views

ConceptWith respect of given number n, the task is to verify whether n is a Trojan Number or not. Trojan Number is defined as a number that is a strong number without a perfect power. We can say that a number n is treated as a strong number if, for every prime divisor or factor p of n, p^2 is also a divisor. We can say in another way, every prime factor appears at least twice. We should remember that all Trojan numbers are strong. But it is not true for vice-versa that means, not all strong numbers are Trojan ...

Read More

Check if a number is an Achilles number or not in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 267 Views

ConceptWith respect of given positive integer n, the task is to verify if n is an Achilles number or not. We have to print 'YES' if N is treated as an Achilles number else print 'NO'.Achilles number: With respect of Mathematics, an Achilles number is defined as a number that is powerful (A number N is said to be Powerful Number if it has been noted that for every prime factor p of it, p^2 also divides it) but not a perfect power.In following, the first few Achilles number are displayed72, 108, 200, 288, 392, 432, 500, 648, 675, 800, ...

Read More
Showing 1101–1110 of 3,768 articles
« Prev 1 109 110 111 112 113 377 Next »
Advertisements