I recently faced some technical interviews, the questions were:
Q.1 Two Strings are given “Hello” & “World”. Print Unique
Characters Present in first and not in the second stringOUTPUT:
He.
My Answer: Compare each character of one string to with every other character of second, not optimal at all (wrong, obviously).
Q.2
ABCABBABCAB, OUTPUT:4A5B2C`, (basically count occurrence of each character)
do this in one pass, not multiple traversal in string, there where other
Again do this in optimal way.
Similarly, there where few other question too..
Question which arises at core to me is:
-
Which data structure from collection framework will help me to handle such scenarios in most optimum way; and
-
Which particular data structure from Java Collection Framework to be used when and why?
Also, If there are books for such topics, do tell
Any Help-Books, References and Links will be of great help in learning and understanding.
IMPORTANT: I need real time scenarios, where which the data structure is implemented
I have studied, Collection API, not throughly, but a summarised idea of hierachy and major data structure classes. i know how to use them, but where and why exactly use them eludes me?
1 Answer