Double Semaphore Solution
\nimport java.util.concurrent.Semaphore;\n\n\nclass FooBar {\n    private int n;\n    private static Semaphore foo = new Semaphore(0);\n    private static Semap
```\nimport java.util.concurrent.Semaphore;\n\n\nclass FooBar {\n    private int n;\n    private static Semaphore foo = new Semaphore(0);\n    private static Semaphore bar = new Semaphore(0);\n    public FooBar(int n) {\n        this.n = n;\n    }\n    \n\n    public void foo(Runnable printFoo) throws InterruptedException {\n        \n        for (int i = 0; i < n; i++) {\n \n        \t// printFoo.run() outputs "foo". Do not change or remove this line.\n        \tprintFoo.run();\n            foo.release();\n            bar.acquire();\n\n        }\n    }\n\n    public void bar(Runnable printBar) throws InterruptedException {\n        \n        for (int i = 0; i < n; i++) {\n            // printBar.run() outputs "bar". Do not change or remove this line.\n            foo.acquire();\n        \tprintBar.run();\n            bar.release();\n        }\n    }\n}\n```
[]