Meta VO Coding Interview / Online Assessment: Every Unique Item in Input Appears Exactly 3 Times

21 Views
No Comments

Every unique item in the input appears exactly 3 times.

Examples:

  • [1, 1, 1] => true
  • [1, 2, 3] => false

Consider a cache-like data structure with operations such as get and put, where items are inserted and retrieved by key.

MyCache mc = new MyCache(4)
mc.get('a') => None
mc.put('a', 'alligator')
mc.put('b', 'baby')
mc.put('c', 'candy')
mc.put('d', 'door')
mc.put('e', 'elephant')
mc.get('a') => ?

The key idea is to count how many times each distinct value appears and verify that every frequency is exactly 3. For the array examples, a hash map is the simplest solution. If the problem also includes cache operations such as <code>get</code> and <code>put</code>, then the focus shifts to maintaining state efficiently with a hash map plus an ordered structure for updates and lookups.

END
 0