Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Hydrogen peroxide pattern making through threading. This system has to make pattern of Hydrogen peroxides from the users inputted Hydrogen and Oxygen sets. If the system gets proper amount of Hydrogen and Oxygen then this can build a perfect set of Hydrogen peroxides

Notifications You must be signed in to change notification settings

ajpalok/H202_Formation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

H202 Formation

Description

There are two kinds of threads: oxygen and hydrogen. Your goal is to group these threads to form di-Oxyzen-di-Oxide molecules.(H2O2)

There is a barrier where each thread has to wait until a complete molecule can be formed. Hydrogen and oxygen threads will be given releaseHydrogen and releaseOxygen methods respectively, which will allow them to pass the barrier. These threads should pass the barrier in groups of four, and they must immediately bond with each other to form a water molecule. You must guarantee that all the threads from one molecule bond before any other threads from the next molecule do.

In other words:

  • If two oxygen thread arrives at the barrier when no hydrogen threads are present, it must wait for two hydrogen threads.
  • If two hydrogen thread arrives at the barrier when no other threads are present, it must wait for two oxygen thread and another hydrogen thread.

We do not have to worry about matching the threads up explicitly; the threads do not necessarily know which other threads they are paired up with. The key is that threads pass the barriers in complete sets; thus, if we examine the sequence of threads that bind and divide them into groups of three, each group should contain one oxygen and two hydrogen threads.

Write synchronization code for oxygen and hydrogen molecules that enforces these constraints.

Example 1:

Input: water = "HOHO"
Output: "HHOO"
Explanation: "OHOH" and "OOHH" are also valid answers.

Example 2:

Input: water = "OOHOHHOH"
Output: "HHOOHOHO"
Explanation: "HOHOHHOO", "OOHHHHOO", "HHOOHOOH", "HOOHOHOH", "OHOHOHOH", "HHOOOOHH", "HOOHOOHH" and "OOHHOOHH" are also valid answers.

About

Hydrogen peroxide pattern making through threading. This system has to make pattern of Hydrogen peroxides from the users inputted Hydrogen and Oxygen sets. If the system gets proper amount of Hydrogen and Oxygen then this can build a perfect set of Hydrogen peroxides

Topics

Resources

Stars

Watchers

Forks

Languages