Skip to content
Preptima
easyCodingConceptEntryMid

You wrote the correct algorithm and the interviewer stopped at your variable declaration. What did the collection type give away?

A declaration shows whether you chose a structure for its access pattern: Stack or LinkedList where ArrayDeque belongs, a List used for membership tests, a concrete type on a signature. Programming to interfaces helps only if the code stays efficient for every implementation it accepts.

4 min readUpdated 2026-10-09

Answer

Short answer

Your declaration is the first design decision the interviewer can read. It shows whether you picked a structure for the operations the algorithm performs, or reached for whatever you typed last time. The usual giveaways are Stack or LinkedList where ArrayDeque belongs, an ArrayList drained with remove(0), a List used for membership tests, and a concrete type on a method signature. Programming to interfaces is part of it, but only if the code behind the interface is efficient for every implementation it accepts.

Was this answer helpful?

Likely follow-ups

  • Your method takes a Collection, and the caller passes a HashSet. Which of your loop's assumptions just broke?
  • When is it right for a public method to return ArrayList rather than List?
  • You need a stack that holds nulls. ArrayDeque refuses them. What do you do?
  • The interviewer asks for a queue that always yields the smallest element first. Which declaration, and what does poll cost?

Related questions

Further reading