
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7197 Articles for C++

184 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

297 Views
ConceptWith respect of a given Binary Tree, the task is to determine the size of maximum complete sub-tree in the given Binary Tree.Complete Binary Tree – A Binary tree is treated as Complete Binary Tree if all levels are completely filled without possibly the last level and the last level has all keys as left as possible.It has been noted that all Perfect Binary Trees are Complete Binary tree but reverse in NOT true. It has been seen that if a tree is not complete then it is also not Perfect Binary Tree.Input 2 / \ ... Read More

179 Views
ConceptThe article explains a method to solving the problem of finding the LCA of two nodes in a tree by reducing it to a RMQ problem.Examples Lowest Common Ancestor (LCA) of two nodes a and b in a rooted tree T is defined as the node located farthest from the root that has both a and b as descendants.For example, according to below diagram, LCA of node D and node I is node B.We can apply so many approaches to solve the LCA problem. These approaches differ with respect of their time and space complexities.Range Minimum Query (RMQ) is applied on ... Read More

196 Views
ConceptWith respect of given an array arr[] of n positive integers, the task is to determineelements arr[i] and arr[j] from the array such that arr[i]Carr[j] is at most possible. With respect of more than 1 valid pairs, print any one of them.Input arr[] = {4, 1, 2}Output 4 2 4C1 = 4 4C2 = 4 2C1 = 4 (4, 2) is the only pairs with maximum nCr.MethodnCr is treated as a monotonic increasing function, that is n+1Cr > nCr. We can apply this fact to get close to our answer; we will select the max n among all the given integers. In ... Read More

291 Views
ConceptWith respect of given N numbers, the target is to determine the minimum removal of numbers such that GCD of the remaining numbers is larger than initial GCD of N numbers. If it is impossible to increase the GCD, print “NO”.Input b[] = {1, 2, 4}Output1After removing the first element, then the new GCD is 2, which is larger than the initialGCD i.e., 1.Input b[] = {6, 9, 15, 30}Output 3The initial gcd is 3, after removing 6 and 9 to obtain a gcd of 15 which is larger than 3. We can also remove 9 and 15 to get a gcd of ... Read More

263 Views
ConceptWith respect of a given undirected graph of b nodes and a edges, the job is to determine minimum edges needed to build Euler Circuit in the given graph.Input b = 3, a = 2 Edges[] = {{1, 2}, {2, 3}}Output 1By connecting 1 to 3, we can build a Euler Circuit.MethodWith respect of a Euler Circuit to exist in the graph we need that every node should haveeven degree because then there exists an edge that can be applied to exit the node after entering it.Now, there can be two cases −Existence of one connected component in the graphWith respect of ... Read More

227 Views
ConceptGiven A x B Chessboard, the task is to calculate the Maximum numbers of cuts that we can build in the Chessboard so that the Chessboard is not divided into 2 parts.Examples The examples are given below −Input A = 2, B = 4Output Number of maximum cuts = 3Input A = 2, B = 2Output Number of maximum cuts = 1MethodFor A = 2, B = 2 ,we can only build 1 cut (mark in red). If we build 1 more cut then the chessboard will divide into 2 piecesFor A = 2, B = 4 ,we can makes 3 cuts (marks in red). ... Read More

393 Views
ConceptSuppose a board of length p and width q is given, we require to break this board into p*q squares such that cost of breaking is least. For this board, cutting cost for each edge will be given. In a nutshell, we require selecting such a sequence of cutting such that cost is minimized.Examples With respect of above board optimal way to cut into square is −Total minimum cost in above case is 65. It is computed evaluated implementing following steps.Initial Value : Total_cost = 0 Total_cost = Total_cost + edge_cost * total_pieces Cost 5 Horizontal cut Cost = 0 + ... Read More

437 Views
Suppose we have a 2D array. Where each cell of which consists number cost which represents a cost to visit through that cell, we have to find a path from top-left cell to bottom-right cell by which total cost consumed is minimum.So, if the input is like32101661319111448158710111141751234891254221141100331124221then the output will be 340 as (32 + 11 + 14 + 48 + 66 + 13 + 19 + 7 + 34 + 12 + 21 + 42 + 21) = 340To solve this, we will follow these steps −Define cell with x, y coordinate and distance parameter.Define an array matrix of ... Read More

495 Views
ConceptWith respect of given three sorted arrays A, B, and C of not necessarily same sizes, compute the lowest i.e. minimum absolute difference between the maximum and minimum number of any triplet A[i], B[j], C[k] such that they are under arrays A, B and C respectively, i.e., minimize (max(A[i], B[j], C[k]) – min(A[i], B[j], C[k])).Input−A : [ 2, 5, 6, 9, 11 ] B : [ 7, 10, 16 ] C : [ 3, 4, 7, 7 ]Output−1ExplanationWhen we select A[i] = 6 , B[j] = 7, C[k] = 7, we get the minimum difference as max(A[i], B[j], C[k]) - ... Read More