Collections interview questions
List, Dictionary, HashSet, concurrent collections, complexity.
3 questions with answers and explanations · 2 flashcards
Key ideas
List<T>: dynamic array. O(1) index and amortized O(1)Add, O(n)Contains/insert.Dictionary<TKey,TValue>andHashSet<T>: O(1) average lookup; keys need consistentEquals/GetHashCode.SortedDictionary: balanced tree, O(log n).- Don't modify a
List<T>whileforeach-ing it. UseConcurrentDictionaryetc. for multi-threaded access.