Narendra Kumar has Published 196 Articles

Missing even and odd elements from the given arrays in C++

Narendra Kumar

Narendra Kumar

Updated on 20-Dec-2019 10:29:28

205 Views

Problem statementGiven two integer arrays even [] and odd [] which contains consecutive even and odd elements respectively with one element missing from each of the arrays. The task is to find the missing elements.ExampleIf even[] = {10, 8, 6, 16, 12} and odd[] = {3, 9, 13, 7, 11} ... Read More

Mirror of n-ary Tree in C++

Narendra Kumar

Narendra Kumar

Updated on 20-Dec-2019 10:25:57

134 Views

Problem statementGiven a Tree where every node contains variable number of children, convert the tree to its mirrorExampleIf n-ary tree is −Then it’s mirror is −Example Live Demo#include using namespace std; struct node {    int data;    vectorchild; }; node *newNode(int x) {    node *temp = new node; ... Read More

Minimum XOR Value Pair in C++

Narendra Kumar

Narendra Kumar

Updated on 20-Dec-2019 10:21:42

86 Views

Problem statementGiven an array of integers. Find the pair in an array which has minimum XOR valueExampleIf arr[] = {10, 20, 30, 40} then minimum value pair will be 20 and 30 as (20 ^ 30) = 10. (10 ^ 20) = 30 (10 ^ 30) = 20 (10 ^ ... Read More

Minimum value that divides one number and divisible by other in C++

Narendra Kumar

Narendra Kumar

Updated on 20-Dec-2019 10:18:48

122 Views

Problem statementGiven two integer p and q, the task is to find the minimum possible number x such that q % x = 0 and x % p = 0. If the conditions aren’t true for any number, then print -1.ExampleIf p = 3 and q = 66 then answer ... Read More

Minimum value of “max + min” in a subarray in C++

Narendra Kumar

Narendra Kumar

Updated on 20-Dec-2019 10:16:18

321 Views

Problem statementGiven a array of n positive elements we need to find the lowest possible sum of max and min elements in a subarray given that size of subarray should be greater than equal to 2.ExampleIf arr[] = {10, 5, 15, 7, 2, 1, 3} then sum of “max + ... Read More

Minimum value among AND of elements of every subset of an array in C++

Narendra Kumar

Narendra Kumar

Updated on 20-Dec-2019 10:12:55

102 Views

Problem statementGiven an array of integers, the task is to find the AND of all elements of each subset of the array and print the minimum AND value among all those.ExampleIf arr[] = {1, 2, 3, 4, 5} then (1 & 2) = 0 (1 & 3) = 1 (1 ... Read More

Minimum toggles to partition a binary array so that it has first 0s then 1s in C++

Narendra Kumar

Narendra Kumar

Updated on 20-Dec-2019 10:11:16

72 Views

Problem statementGiven an array of n integers containing only 0 and 1. Find the minimum toggles (switch from 0 to 1 or vice-versa) required such the array the array become partitioned, i.e., it has first 0s then 1s.ExampleIf arr[] = {1, 0, 0, 1, 1, 1, 0} then 2 toggle ... Read More

Minimum swaps required to make a binary string alternating in C++

Narendra Kumar

Narendra Kumar

Updated on 20-Dec-2019 10:07:23

247 Views

Problem statementGiven a binary string of even length and equal number of 0’s and 1’s. What is the minimum number of swaps to make the string alternating? A binary string is alternating if no two consecutive elements are equalExampleIf str = 11110000 then 2 swaps are required.AlgorithmCount number of zeroes ... Read More

Minimum Swaps required to group all 1’s together in C++

Narendra Kumar

Narendra Kumar

Updated on 20-Dec-2019 10:04:18

182 Views

Problem statementGiven an array of 0’s and 1’s. The task is to find the minimum number of swaps required to group all 1’s present in the array together.ExampleIf input array = {1, 0, 1, 1, 0, 1} then 1 swap is required. i.e. swap first 0 with last 1.AlgorithmCount total ... Read More

Minimum swaps required to bring all elements less than or equal to k together in C++

Narendra Kumar

Narendra Kumar

Updated on 20-Dec-2019 10:01:08

348 Views

Problem statementGiven an array of n positive integers and a number k. Find the minimum number of swaps required to bring all the numbers less than or equal to k together.ExampleIf input array is = {1, 5, 4, 7, 2, 10} and k = 6 then 1 swap is required ... Read More

Advertisements