Can you define the above?
Then take that definition and write out the steps you would use to apply that definition to a specific array to determine if the definition fits.
Then write the java code...