• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Arrays

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

reply
    Bookmark Topic Watch Topic
  • New Topic