Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Arrays  RSS feed

 
Anshul Srivastava
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if that is an interview question, they are as much interested in how you would approach the problem as what our solution would be. Tell us how you approached the problem first.
 
Anshul Srivastava
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Sir! How can I prepare myself to find the solutions of these problems? Any suggestions ? Do I have to study Data structure and algorithm deeply!
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anshul Srivastava
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Knute Snortum
Sheriff
Posts: 4070
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 55672
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And while you are trying to find the algorithm, you should say things like,
There are many different ways to do this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!