Build a hash table from scratch with separate chaining (each bucket is a
list of [key, value] pairs) and use it to find the first element that
appears more than once in an array.
What to implement
class HashTable {
constructor(size = 32)
put(key, value) // insert or update
get(key) // → value | undefined
has(key) // → boolean
}solve(arr) must return the first value (by index order) that has already
been seen earlier in the array. Return null if no duplicate exists.
Examples
solve([3, 1, 4, 1, 5, 9, 2, 6, 5]) → 1 // 1 is seen twice first
solve(['a', 'b', 'a', 'c', 'b']) → 'a'
solve([1, 2, 3]) → nullHash function — sum of char codes of String(key) modulo size.
Constraints
HashTable class, not a native Map or Set, inside solve.
Sample tests