Created
April 18, 2020 23:29
-
-
Save MagedAhmad/4464f6c0a7b51d550218b60aef2cfda2 to your computer and use it in GitHub Desktop.
Hacker rank new year chaos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function minimumBribes($q) { | |
| $count = 0; | |
| for($i = count($q) -1 ; $i >= 0; $i--) { | |
| if($q[$i] - ($i+1) > 2) { | |
| print "Too chaotic" . "\n"; | |
| return; | |
| } | |
| for($j = $q[$i] - 2 > 0 ? $q[$i] - 2: 0 ; $j < $i; $j++) { | |
| if($q[$j] > $q[$i]) { | |
| $count++; | |
| } | |
| } | |
| } | |
| print $count . "\n"; | |
| return; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment