Narendra Kumar has Published 191 Articles

Median in a stream of integers (running integers) in C++

Narendra Kumar

Narendra Kumar

Updated on 10-Feb-2020 10:23:36

144 Views

Problem statementGiven that integers are read from a data stream. Find median of elements read so for in an efficient wayAfter reading 1st element of stream - 10 -> median - 10After reading 2nd element of stream - 10, 20 -> median - 15After reading 3rd element of stream - ... Read More

Mean and Mode in SQL Server

Narendra Kumar

Narendra Kumar

Updated on 10-Feb-2020 10:08:33

2K+ Views

Problem statementMean is the average of the given data set calculated by dividing the total sum by the number of values in the data set.Mode of a data set is the value that appears most frequently in a series of dataIf our dataset is {1, 2, 3, 4} then mean ... Read More

Maximum XOR value of a pair from a range in C++

Narendra Kumar

Narendra Kumar

Updated on 10-Feb-2020 10:00:19

811 Views

Problem statementGiven a range [L, R], we need to find two integers in this range such that their XOR is maximum among all possible choices of two integersIf the given range is L = 1 and R = 21 then the output will be 31 as − 31 is XOR ... Read More

Maximum width of a binary tree in C++

Narendra Kumar

Narendra Kumar

Updated on 10-Feb-2020 09:55:41

299 Views

Problem statementGiven a binary tree, write a function to get the maximum width of the given tree. The width of a tree is the maximum of widths of all levels.Consider below tree −      10      / \     7   4    / \   \ ... Read More

Maximum weight transformation of a given string in C++

Narendra Kumar

Narendra Kumar

Updated on 10-Feb-2020 09:51:50

429 Views

Problem statementGiven a string consisting of only A’s and B’s. We can transform the given string to another string by toggling any character. Thus many transformations of the given string are possible. The task is to find the Weight of the maximum weight transformation.Weight of a sting is calculated using ... Read More

Maximum Sum Path in Two Arrays in C++

Narendra Kumar

Narendra Kumar

Updated on 30-Jan-2020 12:47:36

631 Views

Problem statementGiven two sorted arrays such the arrays may have some common elements. Find the sum of the maximum sum path to reach from beginning of any array to end of any of the two arrays. We can switch from one array to another array only at common elements. Note ... Read More

Maximum sum path in a matrix from top to bottom in C++

Narendra Kumar

Narendra Kumar

Updated on 30-Jan-2020 12:43:02

273 Views

Problem statementConsider a n*n matrix. Suppose each cell in the matrix has a value assigned. We can go from each cell in row i to a diagonally higher cell in row i+1 only [i.e from cell(i, j) to cell(i+1, j-1) and cell(i+1, j+1) only]. Find the path from the top ... Read More

Maximum sum of a path in a Right Number Triangle in C++

Narendra Kumar

Narendra Kumar

Updated on 30-Jan-2020 12:18:47

229 Views

Problem statementGiven a right triangle of numbers, find the largest of the sum of numbers that appear on the paths starting from the top towards the base, so that on each path the next number is located directly below or below-and-one-place-to-the-rightExampleIf given input is: 3 4 5 1 10 7 ... Read More

Maximum sum by adding numbers with same number of set bits in C++

Narendra Kumar

Narendra Kumar

Updated on 30-Jan-2020 12:15:06

296 Views

Problem statementGiven an array of N numbers, the task is to find the maximum sum that can be obtained by adding numbers with the same number of set bitsExampleIf input array is {2, 5, 8, 9, 10, 7} then output would be 14 −Number of set bits in 2 is ... Read More

Maximum subarray sum in O(n) using prefix sum in C++

Narendra Kumar

Narendra Kumar

Updated on 30-Jan-2020 12:05:28

743 Views

Problem statementGiven an Array of Positive and Negative Integers, find out the Maximum Subarray Sum in that ArrayExampleIf input array is − {-12, -5, 4, -1, -7, 1, 8, -3} then output is 9AlgorithmCalculate the prefix sum of the input array.Initialize− min_prefix_sum = 0, res = -infiniteMaintain a loop for ... Read More

Previous 1 ... 3 4 5 6 7 ... 20 Next
Advertisements