Narendra Kumar has Published 191 Articles

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

Narendra Kumar

Narendra Kumar

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

394 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

161 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

108 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

399 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

258 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

478 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

Minimum Sum Path in a Triangle in C++

Narendra Kumar

Narendra Kumar

Updated on 20-Dec-2019 09:58:12

189 Views

Problem statementGiven a triangular structure of numbers, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.ExampleIf input is −   5   7 3  8 1 2 9 6 4 5Then minimum sum is 13 as follows −5 + ... Read More

Minimum sum path between two leaves of a binary trees in C++

Narendra Kumar

Narendra Kumar

Updated on 20-Dec-2019 09:49:26

206 Views

Problem statementGiven a binary tree in which each node element contains a number. The task is to find the minimum possible sum from one leaf node to another.ExampleIn above tree minimum sub path is -6 as follows: (-4) + 3 + 2 + (-8) + 1AlgorithmThe idea is to maintain ... Read More

Minimum sum of two numbers formed from digits of an array in C++

Narendra Kumar

Narendra Kumar

Updated on 20-Dec-2019 09:33:40

509 Views

DescriptionGiven an array of digits which contains values from 0 to 9. The task is to find the minimum possible sum of two numbers formed from digits of the array. Please note that we have to use all digits of given arrayExampleIf input array is {7, 5, 1, 3, 2, ... Read More

Minimum operations required to set all elements of binary matrix in C++

Narendra Kumar

Narendra Kumar

Updated on 22-Nov-2019 11:58:52

226 Views

Problem statementGiven a binary matrix of N rows and M columns. The operation allowed on the matrix is to choose any index (x, y) and toggle all the elements between the rectangle having top-left as (0, 0) and bottom-right as (x-1, y-1). Toggling the element means changing 1 to 0 ... Read More

Advertisements