The most simple solution in C++ beats 82%!!
Intuition\n Describe your first thoughts o/ how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nUsing 2 semaphores.\n- 
# Intuition\n<!-- Describe your first thoughts o/ how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUsing 2 semaphores.\n- smph1 starts at 1: It allows the foo method to run first. When foo is called, it prints "foo" and releases smph2.\n- smph2 starts at 0: It blocks the bar method until foo releases it. When bar is called, it prints "bar" and releases smph1.\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(2n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\nclass FooBar {\nprivate:\n    int n;\n    binary_semaphore smph1{1};\n    binary_semaphore smph2{0};\n\npublic:\n    FooBar(int n) {\n        this->n = n;\n    }\n\n    void foo(function<void()> printFoo) {\n        \n        for (int i = 0; i < n; i++) {\n            smph1.acquire();\n        \t// printFoo() outputs "foo". Do not change or remove this line.\n        \tprintFoo();\n            smph2.release();\n        }\n    }\n\n    void bar(function<void()> printBar) {\n        \n        for (int i = 0; i < n; i++) {\n            smph2.acquire();\n        \t// printBar() outputs "bar". Do not change or remove this line.\n        \tprintBar();\n            smph1.release();\n        }\n    }\n};\n```
['Concurrency', 'C++']