posted 1 year ago

Hello Guys, while learning from head first Java I'm trying to preparing the interview questions which has been asked in different small and medium (Java ) companies based in India. And by seeing those interview questions makes me so afraid that how can I survive with those tough questions which I thought I can solve by learning theories from books. For example that question asked in campus recruitment :

Given an array of size (b-a+1) with number from a to b in sorted form. One number is two times. You have to find out the missing number.

Can you help me with this question how to break it, please ?

Thanks a lot!

Given an array of size (b-a+1) with number from a to b in sorted form. One number is two times. You have to find out the missing number.

Can you help me with this question how to break it, please ?

Thanks a lot!

Anshul Srivastava

Greenhorn

Posts: 16

Campbell Ritchie

Marshal

Posts: 57453

175

posted 1 year ago

Surely you would study data structures and algorithms deeply in order to program. They want to find out how much you know, not how much you have learnt for the interview. Also, as I said, your approach to the problem is as important a the solution.

Start by telling us how you would approach that problem, or more precisely, what you would say in an interview.

Start by telling us how you would approach that problem, or more precisely, what you would say in an interview.

Anshul Srivastava

Greenhorn

Posts: 16

posted 1 year ago

Thanks a ton for reply! Right now I'm not confident enough to find any approach to solution for particular these kind of problems because my knowledge somehow lacking in data structures and algorithms. First of I didn't understand the question properly where it mentioned the size of array(b-a+1). What is that means, can you please describe it?

posted 1 year ago

Say instead of an array you had blocks with numbers on them and you can only look at one block at a time. Say you have a pencil and paper too. How would you do it? Pretend that there are too many blocks to just scan the blocks: what if there were 100 blocks?

Once you have the "way to do it" in your head, and it always works and never fails, you have an algorithm. Then and only then try to translate the algorithm into Java.

Once you have the "way to do it" in your head, and it always works and never fails, you have an algorithm. Then and only then try to translate the algorithm into Java.

All things are lawful, but not all things are profitable.

Campbell Ritchie

Marshal

Posts: 57453

175

posted 1 year ago

And while you are trying to find the algorithm, you should say things like,

There are many different ways to do this.