DEV Community

Metete Welete
Metete Welete

Posted on • Edited on

Print In Order - Leetcode

Print-In-Order

This problem was quite tricky because I had to read it up to 3 times to understand what was required from us for the task.

First, I created an array of the boolean states of the threads, or print order.

The first thread is meant to run before the order two so I left it as is to run and change the boolean state in the initialized array above.

The second thread, I used a while loop to check if the first thread has been run. Do this by checking the boolean state of the first thread in the array. If yes, you can print the second thread and change the boolean state in the array.

The third thread is just like the second thread but now, we use the while loop check the state of the second thread instead of the first thread.

Following this steps, the solution can be implemented in any object oriented programming language.

Top comments (0)