I was asked this question in one of my interviews.
Is there a data structure which has the following 2 capabilities:
1. Constant time access (Random Access), like ArrayList
2. Variable size, like LinkedList
If there is no such data structure, create one on your own.
I believe the answer you’re looking for is “Hash table” (See: “Hash Table” in Wikipedia) as you’ve commented that they were looking for another one beyond
ArrayList(For Java, see: Hashtable)Though be aware that it can be near constant time depending on the hashing algorithm and data set as collisions may occur resulting in a (short) secondary linear search. The Javadoc gives a really good explanation of how this is handled in the Java implementation.