This question is often asked in many companies including amazon,goldmann sachs, Microsoft and google. I also encountered this question in my 2nd round with GoldMann Sachhs, Morgan Stanley. Although they take 6 rounds in all and unfortunately due to some HR discussion i came out, so just wanna share some thoughts on this problem.
Sunday, May 4, 2014
Analytical Questions asked in goldmann Sachhs
Recently while giving an interview for GoldMann Sachhs few weeks back, i was encountered with various analytical questions and thought of sharing with you all these.
1) First question was if u have given a cake and you have to cut that cake into 8 equal parts but only by using 3 cuts, how will you do that?
1) First question was if u have given a cake and you have to cut that cake into 8 equal parts but only by using 3 cuts, how will you do that?
Saturday, May 3, 2014
Object Serialization and How it is done?
We encounter many questions on Object serialization and in this blog i am writing my experience of goldmann sachhs interview when i gave it. They asked me questions on serialization in a series of steps.
Firstly they asked have u heard of Serialization mechanism in java? Then they asked if yes, how it is done. That is if i have to serialize an employee object write a program that would serialize the employee object and store it in a file and then deserialize it.
We all know that Object Serialization refers to a mechanism of saving the state of an object when passing it over a network. Now the question arises is when we serialize an object we all know we have to implement a Serializable interface in our Class and give a unique serialVersion UID for that class. Now the next question arises is if i have to save the state of an object in a file, then write a code that would do that and what if i wont give this unique serialVersionUID in my class.
Firstly they asked have u heard of Serialization mechanism in java? Then they asked if yes, how it is done. That is if i have to serialize an employee object write a program that would serialize the employee object and store it in a file and then deserialize it.
We all know that Object Serialization refers to a mechanism of saving the state of an object when passing it over a network. Now the question arises is when we serialize an object we all know we have to implement a Serializable interface in our Class and give a unique serialVersion UID for that class. Now the next question arises is if i have to save the state of an object in a file, then write a code that would do that and what if i wont give this unique serialVersionUID in my class.
Friday, May 2, 2014
Equals Method In Java and == operator
We all know that likewise hashCode() method equals() method is also defined in java.lang.Object class which is the parent class of every class and by default inherited in any class which we write. Now along with the pedagogy of hashCode(), we have equals method to which interviewers often ask and confuse us with "The HashCode() and Equals() Contract".
Before deep diving into "equals()" method of java i will first like to compare the difference between "==" and "equals" methods which might confuse developers at many instances.
Lets say, i have an Integer Object,i.e
Integer i=10;
Integer j=i;
The "==" operator, tests to see if the two object reference variables refer to the exact same instance of an object whereas The equals() method in java tests to see if the two objects being compared to each other are equivalent but they need not be the exact same instance of the same Object.
Before deep diving into "equals()" method of java i will first like to compare the difference between "==" and "equals" methods which might confuse developers at many instances.
Lets say, i have an Integer Object,i.e
Integer i=10;
Integer j=i;
The "==" operator, tests to see if the two object reference variables refer to the exact same instance of an object whereas The equals() method in java tests to see if the two objects being compared to each other are equivalent but they need not be the exact same instance of the same Object.
Thursday, May 1, 2014
LinkedList Traversal and finding nth node from last in a linked list
We all know that java provides with an API inbuild which has LinkedList class implementing the List interface, but here we are not using any inbuilt API and we are creating a linked list by our own and finding the nth node from last using our own linkedlist class.
This question was asked me during goldmann Sachhs interview, as u people know goldmann sachhs has this procedure of having 6 rounds. I went till last round of GS, although due to some HR discussion i didnt joined but thought to discuss with you, the question which they asked.
So the question was: I have a linked list and i want to find the nth node from the last in a linked list.
This question was asked me during goldmann Sachhs interview, as u people know goldmann sachhs has this procedure of having 6 rounds. I went till last round of GS, although due to some HR discussion i didnt joined but thought to discuss with you, the question which they asked.
So the question was: I have a linked list and i want to find the nth node from the last in a linked list.
HashCode and Equals--> All time favourite
We all know that there are two methods hashCode() and equals() present in Object class. We have always heard of that hashCode is used to give the hashcode of an object which is nothing but the memory address of the object stored and equals is used for equivalence relation match or to test whether two objects are equal or not.
Well this sounds good, but a lack of proper knowledge in these aspects will lead you to in trouble and when the interviewer asks about these concepts in detail, you will definitely get confused. So to make it more easy to understand and to practically implement these methods in our application, i have come up with this post.
HashCode method is defined in java.lang package which is by default inherited in any class. The hashCode method returns an integer value which is nothing but it is derived by mapping the memory address to an integer value. It is a native method defined in Object class of java.lang package that is it is implemented directly in the native code in the JVM.
Well this sounds good, but a lack of proper knowledge in these aspects will lead you to in trouble and when the interviewer asks about these concepts in detail, you will definitely get confused. So to make it more easy to understand and to practically implement these methods in our application, i have come up with this post.
HashCode method is defined in java.lang package which is by default inherited in any class. The hashCode method returns an integer value which is nothing but it is derived by mapping the memory address to an integer value. It is a native method defined in Object class of java.lang package that is it is implemented directly in the native code in the JVM.
Finding the number of one's in an array of zeroes and ones with O(n) complexity.
This is although a simple question but many people might not be aware of this one as when we encounter such problems we feel dumbstruck at one instance. So its better to prepare for such questions, although they look easy but its difficult to get an idea at that time.
This one was asked me during manhatan associates interview question.
So the problem is : You have given an array of zeroes and ones. Now you have to calculate the number of ones and zeroes in that array with the most efficient approach. When you are given first time this problem the basic approach with which a fresher or even an experienced guy having a work ex of 2 years also think in this way:
This one was asked me during manhatan associates interview question.
So the problem is : You have given an array of zeroes and ones. Now you have to calculate the number of ones and zeroes in that array with the most efficient approach. When you are given first time this problem the basic approach with which a fresher or even an experienced guy having a work ex of 2 years also think in this way:
Finding the sub array from an array of positive and negative integers havng maximum sum
Few months back, i went to gave GoldMann Sachhs interview and i was puzzled with this interview question:
They told me you have give an array of positive and negative integers and you have to find the sub array from the given array which sums up to the maximum.
For example:- if you have
{-2, -3, 4, -1, -2, 1, 5, -3}
If you see the above series you have a set of negative and positive numbers and now you have to find the first sub array which has the maximum sum, it can contain either one element or a set of elements.
They told me you have give an array of positive and negative integers and you have to find the sub array from the given array which sums up to the maximum.
For example:- if you have
{-2, -3, 4, -1, -2, 1, 5, -3}
If you see the above series you have a set of negative and positive numbers and now you have to find the first sub array which has the maximum sum, it can contain either one element or a set of elements.