Beats 100% c++ soln; Multithreading; easy to understand
class ZeroEvenOdd {\nprivate:\n    int n;\n    int i;\n    int turn;\n    mutex m;\n    condition_variable cv;\npublic:\n    ZeroEvenOdd(int n) {\n        this-
class ZeroEvenOdd {\nprivate:\n    int n;\n    int i;\n    int turn;\n    mutex m;\n    condition_variable cv;\npublic:\n    ZeroEvenOdd(int n) {\n        this->n = n;\n        this->i=1;\n        this->turn=0;\n    }\n\n    // printNumber(x) outputs "x", where x is an integer.\n    void zero(function<void(int)> printNumber) {\n        unique_lock<mutex>lk(m);\n        while(i<=n)\n        {\n            while(turn!=0)cv.wait(lk);\n            if(i<=n)printNumber(0);\n            if(i%2==0)turn=1;\n            else turn=2;\n            cv.notify_all();\n        }\n    }\n\n    void even(function<void(int)> printNumber) {\n        unique_lock<mutex>lk(m);\n        while(i<=n)\n        {\n            while(turn!=1)cv.wait(lk);\n            if(i<=n)printNumber(i);\n            ++i;\n            turn=0;\n            cv.notify_all();\n        }\n    }\n\n    void odd(function<void(int)> printNumber) {\n        unique_lock<mutex>lk(m);\n        while(i<=n)\n        {\n            while(turn!=2)cv.wait(lk);\n            if(i<=n)printNumber(i);\n            ++i;\n            turn=0;\n            cv.notify_all();\n        }\n    }\n};
['C']