Find the minimum and maximum in the array

Here are few question we find on finding min and max in the array, but array type changes. Unsorted 1D array Find the maximum (OR minimum) in an array Find the maximum AND minimum in an array with min number of comparisons Find the max and second maximum in an array (likewise for minimum) Find the max and nth max in an array Rotated Sorted array Find the minimum element in the rotated sorted array. [Read More]

Find row with maximum number of 1s in sorted matrix

Problem: You are given a MxN matrix with each row sorted. Matrix is having only 0′s and 1′s. You have to find row wotth maximum number of 1′s. eg. matrix given: 000111 001111 011111 000011 111111 // row with max number of 1′s Method 1: Brute force approach Traverse the matrix row wise and count number of 1′s. If the number of 1′s is greater than max count than store index of row. [Read More]

Find an element in matrix in which rows and columns are sorted

Problem Given a matrix in which each row and each column is sorted, write a method to find an element in it. Example 1 4 7 13 2 5 9 15 3 6 10 16 Solution Here we can have 2 cases - Case when array is sorted such that last element of nth row is less than first element of n+1 th row Generic case - simply put rows and columns CASE 1 - If last element of each row is less than first element of next row [Read More]