Author: dharam

Matrix Transformation to make rows and columns zero

Introduction Another interview question about matrices. Matrices have been of great interest in programming and Linear Algebra and a matter of study for most of the programmers. The problem statement follows: "Given a matrix A of size M * N where M is the number of rows and N is the number of columns and each of its cell A[i][j] is populated with either zero or one. Transform the matrix such that if there exists a cell A[i][j] = 0 then the row i and column j is zero in the resultant matrix". You must not use extra space and try to solve it in lowest possible running time. Understanding...
Read More

Left Hand Projection of a Tree

Introduction Another interesting interview question, this question has many forms. One of the form is print the left hand projection of a tree or right hand projection of a tree or so on. Also, this problem can be specialized for a binary tree, ternary tree or n-ary tree, it really doesn't matter, the concept is the same. We will just try and print the left hand projection and I will add a note on how to print the right had project and you can try that yourself. Understanding the problem - Left Hand Projection of a Tree Let us consider the below tree for our problem statement. What is...
Read More

Filling Wine Glasses Interview Question

Introduction This is another interesting interview question and took me sometime to think for an answer. The problem statement goes as follow: "There are wine glasses stacked such that the top level has one glass, the second level has two glasses, the third one has three glasses and so on. Imaging that the levels are deep enough. Each of the glass in the stack has volume u. Now given a jug of volume V full of wine such that V >= u, find the lowest level where wine can reach." Analyzing the problem statement Here is a supporting image for the problem statement. Now I pick up the ju...
Read More

Student Enrollment Interview Question

Introduction This is another interview question which I find interesting. The problem statement goes as follow: "Its the beginning of a new academic year and I am a teacher of Data Structures and Algorithm subject. Many students with distinct roll numbers want to enroll for the class. After sometime few students wanted to opt out from the enrollment because they found some other subject much more interesting. Now, I also have a teaching assistant who can ask me the roll number of a student who is still enrolled into my class. It is not mandatory to tell him a different roll number every ti...
Read More

Polynomial Operations

Introduction This is a famous interview question where it is asked to write program for simple arithmetic polynomial operations. The operation may include adding, subtracting and multiplication of two polynomials (mostly in one variable). For those who want to refresh their knowledge of polynomials, I would include a section below: Understanding Polynomials Polynomials are mathematical expressions of the form a1xnym + a2xn-1ym-1+ . . . + akxn-ky + . . . + anx + an+1. The above polynomial is said to be a polynomial in two variables (x and y). a1xn + a2xn-1 + a3xn-2 + . . . + an-1x + ...
Read More

The Details of Object Class in Java

Introduction With some clarity in the Type Definition in Java, now it is time to know some details of the language. If you missed the critical posts in this series, please visit the link More about reference types in Java. In this post, I trust that you have knowledge about what I wrote in the above link. We will primarily discuss some core classes and their properties in the language. The Object class This Object class is a super class for all other classes. Please note that it is a super class only for all the classes, there are times when people get confused or have doubts if the inte...
Read More

More about Reference Types in Java

Introduction This post is about the Reference Types in Java and it is a continuation of the post Learning Java the Right Way. In the previous post we discussed about the Reference Types and Values. We will continue that discussion further. Also, the Java programming language has a lot to offer in terms of Generics, where it becomes almost mandatory to understand about the Types in detail. Type Declaration Identifiers and Type Names Now on, whenever we talk about the Types it would mostly be the Reference Types in Java. As Java is an object oriented language, even the primitive types h...
Read More