Prateek Jangid has Published 190 Articles

C++ Pairwise Swap Elements of a Given Linked List

Prateek Jangid

Prateek Jangid

Updated on 25-Nov-2021 09:59:09

277 Views

To solve a problem in which we are required to swap the pairwise nodes present in a linked list and then print it, for exampleInput : 1->2->3->4->5->6->NULL Output : 2->1->4->3->6->5->NULL Input : 1->2->3->4->5->NULL Output : 2->1->4->3->5->NULL Input : 1->NULL Output : 1->NULLThere are two ways ... Read More

C++ Pairwise Swap Leaf Nodes in a Binary Tree

Prateek Jangid

Prateek Jangid

Updated on 25-Nov-2021 09:55:10

198 Views

Given a binary tree. The task is to pairwise swap the leaf nodes, for example −Input −Output −We will keep track of two pointers that point to the two adjacent leaf nodes and swap their values in the given problem.Approach to Find the SolutionIn this approach, we traverse the tree, ... Read More

C++ Largest Subset with Sum of Every Pair as Prime

Prateek Jangid

Prateek Jangid

Updated on 25-Nov-2021 09:52:03

93 Views

To find the largest subset from the given array in which the sum of every pair is a prime number. Assuming maximum element is 100000, for example −Input: nums[ ] = { 3, 2, 1, 1 } Output: size = 3, subset = { 2, 1, 1 } Explanation: Subsets ... Read More

C++ Largest Subtree having Equal No of 1's and 0's

Prateek Jangid

Prateek Jangid

Updated on 25-Nov-2021 09:49:47

112 Views

Given a binary tree. Now we are tasked to find the largest subtree having an equal number of 1's and 0's; the tree only contains 0's and 1's.Approach to Find the SolutionIn this approach, we are going to replace all the nodes with values of 0 to -1. Doing this ... Read More

C++ Program to find the Largest Divisible Subset in Array

Prateek Jangid

Prateek Jangid

Updated on 25-Nov-2021 09:48:55

181 Views

This tutorial will discuss a problem where we are given an array of distinct positive integers. We need to find the largest subset such that for every pair larger element is divided by a smaller element, for example −Input: nums[ ] = { 1, 4, 2, 6, 7} Output: 1 ... Read More

C++ Program to find the Largest Divisible Pairs Subset

Prateek Jangid

Prateek Jangid

Updated on 25-Nov-2021 09:44:14

145 Views

To solve a problem in which we are given an array consisting of distinct elements. Now our task is to find the subset such that every pair is evenly divisible, i.e, every large element is divisible by every smaller element, for example.Input : arr[] = {10, 5, 3, 15, 20} ... Read More

Numbers that are Bitwise AND of At Least One Non-Empty Sub-Array using C++

Prateek Jangid

Prateek Jangid

Updated on 25-Nov-2021 09:39:39

87 Views

To solve a problem where we are given an array, and we need to find all possible integers which are bitwise AND of at least one not empty subarray, for example −Input : nums[ ] = { 3, 5, 1, 2, 8 } Output : { 2, 5, 0, 3, ... Read More

C++ Program to find Numbers in a Range with Given Digital Root

Prateek Jangid

Prateek Jangid

Updated on 25-Nov-2021 09:38:25

150 Views

The sum of its digit can find the digital root of a number; if the sum is a single digit, it is a digital root. In this tutorial, we will discuss a problem where we are given a range of numbers and an integer X, and we need to count ... Read More

C++ Program to find Number Whose XOR Sum with Given Array is a Given Number k

Prateek Jangid

Prateek Jangid

Updated on 25-Nov-2021 09:35:54

366 Views

To solve a problem in which, given, we are tasked to find the number such that the XOR sum of a given array with that number becomes equal to k, for example.Input: arr[] = {1, 2, 3, 4, 5}, k = 10 Output: 11 Explanation: 1 ^ 2 ^ 3 ... Read More

Find the Number Whose Sum of XOR with Given Array Range is Maximum using C++

Prateek Jangid

Prateek Jangid

Updated on 25-Nov-2021 09:31:43

158 Views

To solve a problem in which we are given an array and some queries. Now in each query, we are given a range. Now we need to find a number such that the sum of their xor with x is maximized, for exampleInput : A = {20, 11, 18, 2, ... Read More

Advertisements