There are two kinds of atom threads: hydrogen and oxygen. Coordinate them so they pass a barrier in groups that can form water molecules.
The judge creates one thread for every character in water. A hydrogen thread calls hydrogen(releaseHydrogen), while an oxygen thread calls oxygen(releaseOxygen). The supplied callbacks output H and O respectively.
A thread must wait until a complete molecule can be formed. Every group of threads that passes the barrier must contain exactly two hydrogen threads and one oxygen thread, and all three atoms in one molecule must bond before any atom in the next molecule bonds.
In other words:
H characters and one O character.Implement synchronization inside the H2O class. The judge supplies and starts the atom threads, so your implementation should coordinate the method calls rather than create threads itself.
The judge also preloads the standard concurrency and callback APIs for each supported language. You do not need to add import, include, or using statements.
Input:
Output:
Explanation: "HHO", "HOH", and "OHH" are all valid because the single group contains two hydrogens and one oxygen.
Input:
Output:
Explanation: The output contains two consecutive valid molecule groups. Other outputs are valid as long as each group of three contains two H characters and one O character; examples include "HOHHHO", "OHHHHO", "HHOHOH", and "OHHOHH".
3 * n == water.length1 <= n <= 20water[i] is either H or O.water contains exactly 2 * n hydrogen atoms.water contains exactly n oxygen atoms.Input
water = "HOH"
Output
HHO
Run is a quick check against the first couple of scenarios, which is roughly what these examples describe. Submit puts your class under the full set, which stays hidden.

