Water overflowing from glass arranged in form of triangle

Glasses are arranged in the form of triangle (on top of each other) as shown below: 1 2 3 4 5 6 7 8 9 […]

Count number of zeros in a Row-wise Col-wise sorted binary matrix

Given a binary matrix with all rows and col sorted. Write code to count the number of zeros in that matrix. For example, if the […]

Rectangles in a matrix

Given a character matrix in which some of the cells have alphabets written on them while other cells are empty (empty cells contains character ‘-‘ […]

Sum of rectangle region in a given matrix

Given a matrix of integers of order M*N and coordinates of a rectangular region in the matrix, write code to find the sum of all […]

Build binary tree from ancestor matrics

You are given the Ancestor matrix of a Binary tree, write an Algorithm to construct the corresponding tree. For example, the below tree: Will have […]

Print both diagonals of a matrix

Given a matrix of order N*N, write code to print both the diagonals of that matrix. For example: the matrix and its 2 diagonals are […]

Print elements of a matrix in diagonal order

Given a square matrix of order N*N, write code to print all the elements in the order of their diagonal. For example, in the below […]

Islands in a two dimensional array

Each element in the array is connected to eight other elements (toward top, down, left and right). For example, the zero below is connected to […]

Transpose of non-symmetric matrix

Given a M*N order matrix, which is stored in an array in a row-major order. eg. if the  matrix is of order 2*4 with below […]

Search in a matrix sorted on rows & columns

Given a matrix whose each row and column is sorted as shown below 10 20 30 40 15 25 35 45 27 29 37 48 […]