Meta software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
No verified questions yet for Meta.
LRUCache(int capacity): Initializes the cache with a positive size capacity.int get(int key): Returns the value of the key if the key exists, otherwise returns -1.void put(int key, int value): Update the value of the key if present, or add the key-value pair if not existing. When the cache reaches its capacity, it should invalidate the least recently used item before inserting a new item.Example 1:LRUCache(2); cache.put(1, 1); cache.put(2, 2); cache.get(1); cache.put(3, 3); cache.get(2); cache.put(4, 4); cache.get(1); cache.get(3); cache.get(4);1; -1; 3; 4Constraints:capacity is always positive and will not exceed 1000get and put will always be called with valid keys.Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free