Implement an Atomic Counter (Thread-Safe Counter)

Implement a thread-safe counter AtomicCounter.

APIs

  • increment() -> int: atomically increments by 1 and returns the new value.
  • get() -> int: returns the current value.

Requirements

...

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Standard Input
Execution Result: