Array Trade-offs
Advantages: O(1) indexed access.
Advantages: excellent cache locality because elements are contiguous.
Advantages: low per-element memory overhead.
Advantages: efficient sequential iteration.
Disadvantages: fixed-size arrays cannot grow without reallocation.
Disadvantages: middle insertion and deletion are O(n).
Disadvantages: resizing a dynamic array can temporarily require additional memory.
Disadvantages: inserting into a full array may require allocating and copying to a larger array.
If you need to store a list of user IDs that you’ll frequently access by index, how would you implement it with an array, and what happens if you need to add an element beyond its current size?
Can you explain what happens in memory when you declare an int[10] in Java versus a List<Integer>?
We have a feature that processes a stream of events and stores the last 1,000 events in memory. We initially used an array but observed occasional OutOfMemory errors. Walk me through why that might happen and what alternative you’d consider.
During a recent sprint, a teammate replaced a linked list with an array to improve lookup speed, but the code started failing when inserting elements in the middle. Why did the change break, and how would you fix it while keeping performance in mind?
Our service caches user profile objects in a fixed‑size array for fast index‑based retrieval, but as traffic grew the cache hit rate dropped due to poor eviction handling. How would you redesign the cache, weighing the array’s O(1) access against its lack of dynamic resizing and eviction?
We need to store a massive matrix of sensor readings (billions of entries) in memory for real‑time analytics. Discuss the trade‑offs of using a flat contiguous array versus a more complex data structure, considering memory fragmentation, cache locality, and scalability.
A legacy codebase across multiple teams uses large static arrays for configuration data, making deployments fragile when the config size changes. How would you lead a migration strategy to a more flexible structure while minimizing risk and ensuring backward compatibility?
In a high‑frequency trading platform, some components still rely on fixed‑size arrays for deterministic latency. As the system evolves, how would you evaluate whether to replace those arrays with dynamic structures, considering latency guarantees, memory safety, and cross‑team impact?