Java Solution
\nclass FooBar {\n    private int n;\n    boolean l = true;\n\n    public FooBar(int n) {\n        this.n = n;\n    }\n\n    public synchronized void foo(Runnab
```\nclass FooBar {\n    private int n;\n    boolean l = true;\n\n    public FooBar(int n) {\n        this.n = n;\n    }\n\n    public synchronized void foo(Runnable printFoo) throws InterruptedException {\n        \n        for (int i = 0; i < n; i++) {\n            while(!l)\n            {\n                wait();\n            }\n        \tprintFoo.run();\n            l = false;\n            notify();\n        }\n    }\n\n    public synchronized void bar(Runnable printBar) throws InterruptedException {\n        \n        for (int i = 0; i < n; i++) {\n        \twhile(l)\n            {\n                wait();\n            }\n        \tprintBar.run();\n            l = true;\n            notify();\n        }\n    }\n}\n```
[]