After you implement an algorithmic solution in Java, the interviewers ask follow-up questions and request modifications. Answer/discuss (and, where relevant, describe how you would change code):
-
Change request / refactor:
A new requirement arrives (e.g., different input format, extra validation, new edge case, different return type). How do you adjust the code while keeping it readable and testable?
-
Large data handling:
If input size grows significantly, how do you reason about
time complexity
,
memory usage
, and potential bottlenecks in Java? What changes might you make?
-
Collections choice:
Which Java collections would you choose (e.g.,
ArrayList
,
LinkedList
,
HashMap
,
TreeMap
,
Deque
/
Stack
) and why? What are common pitfalls?
-
Generics:
Explain how Java generics work, trade-offs, and common issues (e.g., type erasure, wildcards).
-
Exceptions:
Discuss checked vs unchecked exceptions, best practices for throwing/catching, and how you would design error handling for invalid input.
-
Testing:
What unit tests would you write (e.g., with JUnit)? How do you cover boundary cases and regression for the new requirement?