Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
C++ Articles
Page 39 of 597
Even size subtree in n-ary tree in C++
In this problem, we are given an adjacency list that denotes an n-ary tree. Our task is to find the number of even size subtree in n-ary tree. N-ary tree is defined as a collection of nodes normally represented hierarchically in the following manner.The tree is started at the root node.Each node of the tree maintains a list of pointers to its child nodes.The number of child nodes is less than or equal to m.Let’s take an example to understand the problem, Input: Output: 4Explanation: Tree rooted with 7 has an even size.Tree rooted with 2 has an even size.Tree rooted with 0 has an ...
Read MoreMaximum product subset of an array in C++ program
In the problem, we are given an array arr[] of n integer values. Our task is to create a program to find the Maximum product subset of an array.Problem Description − Here, we need to calculate the maximum possible product of a subset of elements of an array.Subset − An array sub[] is a subset of array arr[] if all elements of sub[] are present in arr[].Let’s take an example to understand the problem, Inputarr[] = {4, 5, 2, −1, 3}Output40ExplanationSubset sub[] = {4, 5, 2} Prod = 4*5*2 = 40Solution ApproachA simple and easy approach to solve the problem ...
Read MoreEven-odd turn game with two integers in C++
In this problem, we are given three integer values A , B and T. Our task is to create a program to play Even-odd turn game with two integers. The two integer value are :T, that denotes the number of turns in the game.A denotes the value for player1B denotes the value for player2If the value of T is odd, the value of A is multiplied by 2.If the value of T is even, the value of B is multiplied by 2.We need to find and return value of max(A, B) / min(A, B) at the end.Let’s take an example to understand ...
Read MoreMaximum size of sub-array that satisfies the given condition in C++ program
In this problem, we are given an array arr[] of n integers. Our task is to create a program to find the maximum size of sub-array that satisfies the given condition.Problem Description − We need to find the length of largest subarray that satisfies any one of the below condition, arr[k] > arr[k+1], if k is odd and arr[k] < arr[k+1], if k is even. For all elements of the subarray.arr[k] < arr[k+1], if k is odd and arr[k] > arr[k+1], if k is even. For all elements of the subarray.Here, k is the index of the element of the ...
Read MoreEvil Number with Example in C++
In this problem, we are given an array a number N. Our task is to check whether the number is an evil Number or Odious Number. Evil Number: It is a positive number which has an even number of 1’s in its binary expansion.Example: 5, 17 Odious Number: It is a positive number which has an odd number of 1’s in its binary expansion.example : 4, 6Let’s take an example to understand the problem, Input: N = 65Output: Evil NumberExplanation: Binary Expansion of 65 : 1000001Solution Approach: A simple solution to the problem is by finding the binary expansion of the number and then counting the number of 1’s ...
Read MoreMaximum sub-tree sum in a Binary Tree such that the sub-tree is also a BST in C++ program
In this problem, we are given a binary tree BT. Our task is to create a program to find the Maximum sub−tree sum in a Binary Tree such that the sub−tree is also a BST.Binary Tree has a special condition that each node can have a maximum of two children.Binary Search Tree is a tree in which all the nodes follow the below−mentioned propertiesThe value of the key of the left sub-tree is less than the value of its parent (root) node's key.The value of the key of the right subtree is greater than or equal to the value of ...
Read MoreMaximum subarray size, such that all subarrays of that size have sum less than k in C++ program
In this problem, we are given an array arr[] consisting of n positive integers and an integer k. Our task is to create a program to find the Maximum subarray size, such that all subarrays of that size have sum less than k.Problem Description − we need to find the largest size of a subarray, such that all subarray created of the size from the elements of the array will have the sum of elements less than or equal to k.Let’s take an example to understand the problem, Inputarr[n] = {4, 1, 3, 2}, k = 9Output3ExplanationAll subarrays of size ...
Read MoreMaximum subarray sum in an array created after repeated concatenation in C++ Program
In this problem, we are given an array arr[] of size n and an integer k. Our task is to create a program to find the maximum subarray sum in an array created after repeated concatenation.Problem Description − We will find the maximum sum of the subarray is taken from the array which is created after repeating arr, k times.ExampleLet’s take an example to understand the problem.Inputarr[] = {−9, −5, 14, 6} k = 2Output26ExplanationNew array after repeating : {−9, −5, 14, 6, −9, −5, 14, 6} Subarray with maximum sum = {14, 6, −9, −5, 14, 6} Sum = ...
Read MoreExpress an odd number as sum of prime numbers in C++
In this problem, we are given an odd number N. Our task is to express an odd number as the sum of prime numbers.There can be at max three prime numbers while expressing the number.Let’s take an example to understand the problem, Input: N = 55Output: 53 + 2Solution Approach: The odd number can be represented as a sum of primes. Taking these primes into consideration we have three cases.Case 1: If n is a prime number, it is represented as the sum of one prime number n.Case 2: If (n - 2) is a prime number, it is represented as the sum of two ...
Read MoreMaximum sum alternating subsequence in C++ program
In this problem, we are given an array arr[] of n integers. Our task is to create a program to find the Maximum sum alternating subsequence starting from the first element of the array.An alternating subsequence is a subsequence in which elements are increasing and decreasing in an alternating order i.e. first decreasing, then increasing, then decreasing. Here, the reverse alternating subsequence is not valid for finding the maximum sum.Let’s take an example to understand the problem, Inputarr[] = {5, 1, 6, 2, 4, 8, 9}Output27ExplanationStarting element: 5, decrease: 1, increase: 6, decrease: 2, increase:4, N.A. Here, we can use ...
Read More