Code RoomCache computes same key twice
HardPrep Room Coding #1655

Cache computes same key twice

Code reviewConcurrencyAlgorithms & data structuresSenior–Staff~26 min

Review this Java memoizing cache built on ConcurrentHashMap.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 26 min
Mark a line and say what kind of problem it is.0 findings
1private final ConcurrentHashMap<Key, Value> cache = new ConcurrentHashMap<>();
2 
3public Value get(Key k) {
4 if (cache.containsKey(k)) {
5 return cache.get(k);
6 }
7 Value v = expensiveCompute(k);
8 cache.put(k, v);
9 return v;
10}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.