[Beats 100%] Using 2 semaphores - easy to understand
Full code with test suite\nhttps://github.com/Freeze777/SDE-Interviewer-Notes/blob/main/LeetCodeJava/src/main/java/leetcode/concurrency/FooBar.java\n\n# Code\n\
# Full code with test suite\nhttps://github.com/Freeze777/SDE-Interviewer-Notes/blob/main/LeetCodeJava/src/main/java/leetcode/concurrency/FooBar.java\n\n# Code\n```\nclass FooBar {\n    private final int n;\n    private final Semaphore foo = new Semaphore(1);\n    private final Semaphore bar = new Semaphore(0);\n\n    public FooBar(int n) {\n        this.n = n;\n    }\n\n    public void foo(Runnable printFoo) throws InterruptedException {\n        for (int i = 0; i < n; i++) {\n            foo.acquire();\n        \tprintFoo.run();\n            bar.release();\n        }\n    }\n\n    public void bar(Runnable printBar) throws InterruptedException {\n        for (int i = 0; i < n; i++) {\n            bar.acquire();\n        \tprintBar.run();\n            foo.release();\n        }\n    }\n}\n```
['Java']