Shubham Vora has Published 957 Articles

Maximum Absolute difference between any two Level Sum in a Binary Tree

Shubham Vora

Shubham Vora

Updated on 02-Aug-2023 13:44:36

195 Views

In this problem, we will find the maximum absolute difference between the sum of all nodes of any two levels. We can use the queue data structure to traverse through each binary tree level. While traversing each level, we can keep track of the maximum and minimum sum and ... Read More

Maximize Shortest Path between given Vertices by Adding a Single Edge

Shubham Vora

Shubham Vora

Updated on 02-Aug-2023 13:42:20

219 Views

In this problem, we will maximize the shortest path between the vertex 1 to N by adding the edge between two selected vertices. Here, we will track the distance of each node of the graph from the 0th and N − 1 nodes. After that, we will insert the ... Read More

Longest Subarray whose Elements can be Made Equal by Maximum K Increments

Shubham Vora

Shubham Vora

Updated on 02-Aug-2023 13:40:21

444 Views

In this problem, we will find the length of the longest subarray so that we can make all subarray elements the same by adding some positive integer values, and the sum of added numbers to each element shouldn’t increase than K. The naïve approach is to find the cost of ... Read More

Implementation of a Hypergraph

Shubham Vora

Shubham Vora

Updated on 02-Aug-2023 13:38:36

310 Views

In this tutorial, we will learn to implement the hypergraph in C++. Definition − The hypergraph is a special version of the graph. In which the single can connect 2 or more vertices. In a normal graph, the single edge can connect only 2 vertices, but a hypergraph is a ... Read More

Count of Array Elements whose Order of Deletion Precedes Order of Insertion

Shubham Vora

Shubham Vora

Updated on 02-Aug-2023 13:36:59

103 Views

In this problem, we will count the number of elements removed from the array before they are inserted in the array. The logical part for solving the problem is that check for all numbers that its position in the remove[] array before its position in the insert[] array. If yes, ... Read More

Find the Largest Multiple of 3 (Using Queue)

Shubham Vora

Shubham Vora

Updated on 02-Aug-2023 13:31:59

157 Views

In this problem, we will find the largest multiple of 3 using the array elements. The naïve approach is that generate all possible combinations of array elements and check whether it is divisible by 3. In this way, keep track of the maximum possible multiple of 3. The efficient ... Read More

Find the K Closest Points to Origin using Priority Queue

Shubham Vora

Shubham Vora

Updated on 02-Aug-2023 13:29:05

252 Views

In this problem, we will find the K nearest point from the origin in the 2D plane from the given N points. We can use the standard Euclidean distance formula to calculate the distance between the origin and each given point. After that, we can store the points with distance ... Read More

Count of Prime Factors of N to be Added at each Step to Convert N to M

Shubham Vora

Shubham Vora

Updated on 02-Aug-2023 13:22:47

126 Views

In this problem, we will convert the number N to M by adding the one prime factor of N to itself and updating it in each operation. We will use the breadth−first search algorithm to solve the problem. We will find the prime factor of each updated N and insert ... Read More

Construct Complete Binary Tree from its Linked List Representation

Shubham Vora

Shubham Vora

Updated on 02-Aug-2023 13:11:14

703 Views

In this problem, we will convert the linked list to the complete binary tree. We can assume the linked list as an array. The pth element of the linked list is the parent node of the binary tree's 2*p + 1 and 2*p + 2 elements. So, we can traverse ... Read More

Check if the given Permutation is a Valid BFS of a Given Tree

Shubham Vora

Shubham Vora

Updated on 02-Aug-2023 13:05:45

303 Views

In this problem, we will check whether we can get the permutation of 1 to N elements given array using the BFS (Breadth−first search) traversal with the given binary tree. Here, we will traverse the tree and find all possible permutations using the BFS traversal. After that, we can ... Read More

Advertisements