7ms 100% solution using semaphore
\nclass ZeroEvenOdd {\n    private int n;\n    \n    Semaphore z = new Semaphore(1);\n    Semaphore e = new Semaphore(0);\n    Semaphore o = new Semaphore(0);\n
```\nclass ZeroEvenOdd {\n    private int n;\n    \n    Semaphore z = new Semaphore(1);\n    Semaphore e = new Semaphore(0);\n    Semaphore o = new Semaphore(0);\n    \n    int i;\n    public ZeroEvenOdd(int n) {\n        this.n = n;\n        i=0;\n    }\n\n    // printNumber.accept(x) outputs "x", where x is an integer.\n    public void zero(IntConsumer printNumber) throws InterruptedException {\n        \n        \n        while(true)\n        {\n            \n        z.acquire();\n        if(i<n)\n        {\n            \n            printNumber.accept(0);\n            i++;\n        }\n        else\n        {\n            break;\n        }\n        if(i%2==0)\n        {\n            e.release();\n        }\n        else\n        {\n            o.release();\n        }\n        }\n        i++;\n        e.release();\n        o.release();\n    }\n\n    public void even(IntConsumer printNumber) throws InterruptedException {\n        \n        while(true)\n        {\n            \n        \n        e.acquire();\n        if(i<=n)\n        {\n            System.out.println("in even" + i);\n            printNumber.accept(i);\n           \n        }\n        else\n        {\n            break;\n        }\n        z.release();\n        }\n        \n    }\n\n    public void odd(IntConsumer printNumber) throws InterruptedException {\n        \n        while (true)\n        {\n            \n        \n        o.acquire();\n        if(i<=n)\n        {\n            System.out.println("in odd" + i);\n            printNumber.accept(i);\n           \n        }\n        else\n        {\n            break;\n        }\n        z.release();\n        }\n\n    }\n}\n```
[]