Saturday 16 November 2013

Zycus Java Interview for Experienced Professionals. Sharing my experience

Hey guys, yesterday I went for an interview in Zycus (a product based company in Mumbai) for the post of Java developer. I want to share my experience with you.

It was a walk-in. Any one with 1.5 to 4 years of experience in Java development could go.
It had 4 rounds.
The first was general aptitude. Consisted of 10 questions. Total 30 minutes were given. So that comes to 3 minutes per question. The questions were very easy. But since I had no practice of Aptitude type questions I took time. But eventually I got all answers correct. :)
Questions were mostly mathematics based like 1 train-platform question, 1 question on average, 1 on percentage. Few were based on blood relations, series, etc.
We were divided into groups of 5 and asked to solve the first round of general aptitude. All the guys in my group cleared it.

Then the second round. Written Technical Test. I failed in that round!!!!  :'(
There were 2 questions in that round. One was based on applying the algorithm and the second one on coding the algorithm. Total 60 minutes were given which in my opinion are sufficient.
I want you people to be aware of what kind of questions can be asked so that your better prepared. I think I failed because I had appeared on another Java Interview on the same day in another company and I was just too tired. You better be prepared to put full effort and avoid being lazy like I was. :)
The first step to solve the problem is understand it. Think in your mind how to solve it. Prepare a rough pseudo code for the problem before you start writing actual code. Writing Pseudo code first is a very good practice as it gives you a feeling that you can solve the problem, gives you an estimates of time required to write the code, helps you establish the boundary values of indexes for arrays,etc.
I came home and tried to write a program for that and I succeeded this time.
I have commented out few things in the program that were helpful for me to debug it.
Try to copy the code in Eclipse/NetBeans.
Run it as a Java Application.
Understand its logic.
Read the problem statement twice thrice....until you understand it completely.

package mypackage;

/*Problem Statement
 * There is  a grid of size 5 by 5.
 * Each cell in the grid can be alive or dead.
 * An alive cell has a value 1 while a dead cell has a value 0.
 * A first generation of the grid is generated using the following rules.
 *  1.  If an alive cell has less than 2 alive neighbors then it dies as if by starvation.
 *  2.  If an alive cell has 2 or 3 alive neighbors then it survives.
 *  3.  If an alive cell has more than 3 alive neighbors then it dies as if by overcrowding.
 *  4.  If a dead cell has exactly 3 alive neighbors then it lives as if by reproduction.
 *
 *  Second generation of the grid is generated using the same rules as that used for generating        *  first one.
 *  Question 1. Generate first and second generation of grid on paper
 *  Question 2. Generate first and second generation of grid using a program in C/C++/Java.
 * */

(The dark cells are the live ones)
Answer 1.


Answer 2.
public class Test3 {

public static void main(String[] args) {
int inputGrid[][] = {{0,0,0,0,0},{0,1,1,0,0},{0,1,1,0,0},{0,0,1,1,0},{0,0,1,1,0}};
Test3 test3 = new Test3();
int outputGrid[][] = test3. getNextGeneration(inputGrid);
System.out.println("First Generation output");
test3.displayGrid(outputGrid);
outputGrid = test3. getNextGeneration(outputGrid);
System.out.println("Second Generation output");
test3.displayGrid(outputGrid);
}

public int[][] getNextGeneration(int[][] inputGrid){
int row = inputGrid.length;
int column = inputGrid[0].length;
int[][] outputGrid = new int[row][column];
int activeCount = 0;
//System.out.println("Active count.");
for(int i = 0; i < row; i++){
for(int j = 0; j < column; j++){
if(inputGrid[i][j] == 1){    //If the cell is alive.
activeCount = getActiveCount(inputGrid,i,j);
if(activeCount == 2 || activeCount == 3)
outputGrid[i][j] = 1;
}
else{                                 //If the cell is dead.
activeCount = getActiveCount(inputGrid,i,j);
if(activeCount == 3)
outputGrid[i][j] = 1;
}
//System.out.print("i=" + i + " j=" + j);
}
//System.out.println();
}

return outputGrid;
}

//Display the outputGrid.
public void displayGrid(int[][] inputGrid){
int row = inputGrid.length;
int column = inputGrid[0].length;
for(int i = 0; i < row; i++){
for(int j = 0; j < column; j++){
System.out.print(inputGrid[i][j]);
}
System.out.println();
}
}

       //Counts the number of active neighbors.
public int getActiveCount(int[][] inputGrid,int i,int j){
int activeCount = 0;
int noOfIter = 0;
for(int m=-1; m <= 1; m++){
for(int n = -1; n <= 1; n++){
                               //If the array indexes go out of boundary skip the remaining loop and continue to the                                      //next iteration.
if((m == 0 && n == 0) || (m+i) < 0 || (m+i) > 4 || (n+j) < 0 || (n+j) > 4)
continue;
if(inputGrid[m+i][n+j] == 1)
activeCount++;
//noOfIter++;
//System.out.print(" m+i" + (m+i) + " n+j" + (n+j));
}
//System.out.println();
}
//System.out.println("No of iterations:"+ noOfIter);
//System.out.println("Active Count"+ activeCount);
return activeCount;
}
}

If you have a better or more efficient program for the same problem then please add it in comments. It will be added to this blog post along with your name.

After the Written Technical Test comes the third round which is Technical Interview(TI). Although I couldn't qualify for that, got some info from my friend who went through it.
He had to wait for some 4 hours for his turn to come for TI. It lasted for 45 minutes. They started with core Java. The questions were not general. They were tough and demanded thorough knowledge and application of Java concepts. For everything the interviewer wanted a program. They asked to write a program to find the frequency of a string in a string array. My friend used a Map. Added the string as key and its frequency as value. Used the contains() method to find if the map contained the string. If it already contained then he used Object setValue(Object key) method to increment the frequency of the string. If it didn't then he added the key value pair to the map using the  method Object add(Object key ,Object value) keeping the value (frequency ) as 1.

Some useful code for the same program has been suggested by my friend - Sheshadri Talla. Thanks man!!!
Posting it here.

Same output using traditional coding style(without using collections framework)
String strArray[] = {"Amit","Suresh","Suyash","Vimal","Amit","Amit","Suyash","Amit","amit"};
System.out.print("{");
for(int i=0; i=0; j--){
if(temp.equals(strArray[j])){
skip=true;

}

}
for(int k=i+1; k<strArray.length; k++){

if(temp.equals(strArray[k]) && !skip){
count++;
}
}
if(!skip){
System.out.print(temp+"="+count+", ");
}

}
System.out.print("}");

Hope this was helpful. Signing off for today.

No comments:

Post a Comment