• 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

Core Java Real time based questions

 
Ranch Hand
Posts: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers,
I have below Core Java Real time based questions

I attended a interview and was asked below set of qns for data structures and algorithms in java





 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepak Lal wrote:
I attended a interview and was asked below set of qns for data structures and algorithms in java



What were your answers? We can give you hints in the right direction (or confirm that you were correct), if you like.

Henry


PS... BTW, I think you meant "real world" based questions. "realtime" has a very specific meaning in computing, and its not what you are asking here.

 
Deepak Lal
Ranch Hand
Posts: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

Deepak Lal wrote:
I attended a interview and was asked below set of qns for data structures and algorithms in java


What were your answers? We can give you hints in the right direction (or confirm that you were correct), if you like.
Henry
PS... BTW, I think you meant "real world" based questions. "realtime" has a very specific meaning in computing, and its not what you are asking here.



@Henry,I do not know the answers therefore im posting the questions here.If i dont know the answers then what kind of hints can you give me.
@Henry and other Ranchers,It would be pointless to ask you people or post in such forums if i knew the answers. why should i be doing that ???
These are just questions for me.probably you can interpret them as "Just Core Java Questions"
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepak Lal wrote:
@Henry,I do not know the answers therefore im posting the questions here.If i dont know the answers then what kind of hints can you give me.



I can do better than a hint, I can tell you exactly what to do.

This is a interview question. It is also not a multiple choice question, not a question with a one word answer, and not even a question with the short answer.

Never, ever, and I mean, absolutely never, say that you don't know the answer during the interview -- even if you don't know the answer. The reason the question is asked is not to test whether you know the answer, but how you think through a problem.

Go to the board, draw out the problem, brainstorm the problem. And by brainstorm, I mean brainstorm out loud -- make sure the interviewer knows what you are thinking, and how you are approaching the problem. etc. Also, don't be afraid to ask the interviewer for clarification about the problem, during this process -- it demonstrates your thinking (or knowing) when you don't have enough information, and your willingness to go back and get more information from the stakeholders.

Henry
 
Deepak Lal
Ranch Hand
Posts: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1> Linked List data structure should be my answer for Phone book application.but how to search by name and number.correct me if I am wrong
2> i do not know the approach of finding duplicates in 10,000 elements effeciently,except that the fact there is a solution of comparing each element with next one with a complexity if O(n2),but i need an a effecient solution.Did you have a better approach?
3>I really don't know the answer for this.Please help me for this.
 
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For duplicates in 10,000 strings I would write this following code, this code finds duplicates and sorts in ascending order. I don't know whether this is right approach or not.
>
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Algorithm for phone book, take a SortedMap, put all the corresponding key and value pairs in it.

Get the mobile number using map.get("name");

Problem with maps is we can get the value using key, reverse is somewhat difficult. For this get all the keys in the SortedMap into an Object, then compare each and every value with the search value, if returned true, then print the Object value, i.e. the key.
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
chaitanya, please don't provide full solutions. LetThemDoTheirOwnHomework. For what it's worth, your code looked pretty good to me. I just would have used a LinkedHashMap instead of a TreeMap to a) preserve order, and b) have slightly faster lookups.

As for the name to number lookup, your solution would only have worked for exact matching. If I would search for "Rob" I wouldn't find my own number, whereas I would like to find both my number and that of other Robs around.
 
chaitanya karthikk
Ranch Hand
Posts: 806
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[quote=Rob Prime
As for the name to number lookup, your solution would only have worked for exact matching. If I would search for "Rob" I wouldn't find my own number, whereas I would like to find both my number and that of other Robs around.

Thanks Rob for the suggestions, I forgot to mention two things, one is exact matching which you said, and other is what if, if any one put the same value with different key.

I left these things to Deepak only.

chaitanya, please don't provide full solutions. LetThemDoTheirOwnHomework.


Actually I took it as a homework, I too was waiting for someone to judge whether the approaches are right or wrong and sorry, I don't know about this LetThemDoTheirOwnHomework.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepak Lal wrote:1> Linked List data structure should be my answer for Phone book application.but how to search by name and number.correct me if I am wrong


Can you explain why you would choose a linked list? What alternatives are there to a linked list? What are the advantages and disadvantages of a linked list compared to other data structures?
 
reply
    Bookmark Topic Watch Topic
  • New Topic