Jesper de Jong wrote:Ok, so you already have an idea about how to solve the problem. Good that you thought about that before writing code - one mistake that many people make is trying to write code immediately, before they have even thought about what they need to do.
What's stopping you from writing code for this? Did you try writing anything? If yes, then please post your try here. Please explain us what part exactly you're having trouble with.
Campbell Ritchie wrote:That is of course the correct thing to do in an interview. Interview questions are different from real‑life questions.
Chan Ag wrote:Yea, the requirement that 'in it when some element is put then we can get different element' sounds vague. I'm guessing either the interviewer didn't frame the question well or perhaps the OP hasn't stated exactly what was asked.
The idea of adding an element and getting a different element as a result of adding an element sounds uncommon, if not weird. However if the interviewer just meant that the data structure should allow you to return an element at random ( any element -- in no specific order ) from the data structure, you could use a randomization logic for returning the element from any datastructure based on the linked lists ( the general term ) / arrays. You could even use a shuffling operation.
Why do you think you might require data manipulation for returning an item?
Tim Cooke wrote:That's quite vague.
What was your answer?
Tim Cooke wrote:I think what your interviewer was getting at is more like this scenario:
When you want to populate the dependency in another class.
How do you use Spring's Autowire feature to specify what implementation of Country gets injected?