Semaphore using 2 keys and 3 keys

In reply to Shruti Kamble:
No. get() and put() are atomic test and set operations. The results from any other method could be invalid as soon as they are returned.

It’s up to you how you manage the total number of keys available. A semaphore is a resource manager, and there are many ways to manage the number of resources over time.