package leetcode;

/**
 * https://leetcode.com/problems/print-in-order/
 */
public class Problem1114 {
    private static class Foo {
        public Foo() {

        }

        public void first(Runnable printFirst) throws InterruptedException {

            // printFirst.run() outputs "first". Do not change or remove this line.
            printFirst.run();
        }

        public void second(Runnable printSecond) throws InterruptedException {

            // printSecond.run() outputs "second". Do not change or remove this line.
            printSecond.run();
        }

        public void third(Runnable printThird) throws InterruptedException {

            // printThird.run() outputs "third". Do not change or remove this line.
            printThird.run();
        }
    }

    public static void main(String[] args) {
        Problem1114 prob = new Problem1114();
    }
}

@@ -12,16 +12,61 @@
 tcode;%0A%0A
+import java.util.concurrent.CountDownLatch;%0A%0A
 /**%0A * h
@@ -172,16 +172,205 @@
 s Foo %7B%0A
+        private final CountDownLatch latch2 = new CountDownLatch(1);%0A        private final CountDownLatch latch3 = new CountDownLatch(1);%0A        private final Object obj1 = new Object();%0A%0A
         
@@ -384,17 +384,16 @@
 Foo() %7B%0A
-%0A
         
@@ -464,33 +464,32 @@
 ptedException %7B%0A
-%0A
             // p
@@ -578,32 +578,64 @@
 intFirst.run();%0A
+            latch2.countDown();%0A
         %7D%0A%0A     
@@ -700,32 +700,59 @@
 ptedException %7B%0A
+            latch2.await();
 %0A            // 
@@ -845,32 +845,64 @@
 ntSecond.run();%0A
+            latch3.countDown();%0A
         %7D%0A%0A     
@@ -973,16 +973,43 @@
 ption %7B%0A
+            latch3.await();
 %0A       
@@ -1134,105 +1134,7 @@
    %7D
-%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1114 prob = new Problem1114();%0A    %7D
 %0A%7D%0A

Solve problem 1114