Implement the lruCacheGetOutputSum method that simulates an LRU cache and returns the sum of get results.
You are given a cache capacity and a list of operations. Each operation is represented as [type, key, value]. Type 1 means put the key-value pair into the cache. Type 2 means get the key; the value field is ignored.
For every get operation, add the returned value to a running sum. If a key is missing, add -1. Return the final sum of all get results.
An LRU cache removes the least recently used key when capacity is exceeded.
Use a hash map for fast key lookup and a linked order structure to track usage from least recent to most recent. On every get or put of an existing key, move that key to the most recently used position. When inserting a new key beyond capacity, remove the least recently used key.
The problem returns the sum of get outputs so the simulation has one deterministic integer result.
Pseudocode:
function lruCacheGetOutputSum(capacity, operations, size):
cache = empty map
order = empty structure from least recent to most recent
total = 0
for each operation [type, key, value]:
if type == 1:
if key exists:
update value and move key to most recent
else:
if cache size == capacity:
remove least recently used key
insert key and value as most recent
else:
if key exists:
total += cache[key]
move key to most recent
else:
total += -1
return total