Code RoomAtomic increment interleaving simulator
MediumPrep Room Coding #172

Atomic increment interleaving simulator

CodingConcurrencyMid–Senior~25 min

A shared counter starts at 0. N threads each perform one non-atomic increment, implemented as three steps in order: LOAD (read counter into the thread's local register), ADD (local register += 1), STORE (write the local register back to the counter). You are given a schedule: a list of [thread, step] events that is a valid interleaving of these steps (each thread's LOAD precedes its ADD precedes its STORE). Simulate the interleaving and return the FINAL value of the shared counter. Because of lost updates this can be anywhere from 1 to N.

Implement
interleaved_counter(n: int, schedule: list[list]) → int
Examples
in[2,[[0,"LOAD"],[1,"LOAD"],[0,"ADD"],[0,"STORE"],[1,"ADD"],[1,"STORE"]]]out1
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 25 min
InputExpectedGot
[2,[[0,"LOAD"],[1,"LOAD"],[0,"ADD"],[0,"STORE"],[1,"ADD"],[1,"STORE"]]]1not run yetsample