Last active
September 7, 2018 20:19
-
-
Save wontheone1/141d3e5ce7fc62fcb6c1aa9473589775 to your computer and use it in GitHub Desktop.
Hackerrank 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
1 2 3 4 5 6 7 8 ; Indices | |
1 2 3 4 5 6 7 8 ; person-numbers | |
0 0 0 0 0 0 0 0 ; person-numbers - indices | |
0 0 0 0 0 0 0 0 ; accumulated difference | |
; sum of accumulated difference: 0 | |
; Total bribery: 0 | |
1 2 3 4 5 6 7 8 ; Indices | |
1 2 3 5 4 6 7 8 ; person-numbers | |
0 0 0 1 -1 0 0 0 ; person-numbers - indices | |
0 0 0 1 0 0 0 0 ; accumulated difference | |
; sum of accumulated difference: 1 | |
; Total bribery: 1 | |
1 2 3 4 5 6 7 8 ; Indices | |
1 2 5 3 4 6 7 8 ; person-numbers | |
0 0 2 -1 -1 0 0 0 ; person-numbers - indices | |
0 0 2 1 0 0 0 0 ; accumulated difference | |
; sum of accumulated difference: 3 | |
; Total bribery: 2 | |
1 2 3 4 5 6 7 8 ; Indices | |
1 2 5 3 4 7 6 8 ; person-numbers | |
0 0 2 -1 -1 1 -1 0 ; person-numbers - indices | |
0 0 2 1 0 1 0 0 ; accumulated difference | |
; sum of accumulated difference: 4 | |
; Total bribery: 3 | |
1 2 3 4 5 6 7 8 ; Indices | |
1 2 5 3 7 4 6 8 ; person-numbers | |
0 0 2 -1 2 -2 -1 0 ; person-numbers - indices | |
0 0 2 1 3 1 0 0 ; accumulated difference | |
; sum of accumulated difference: 7 | |
; Total bribery: 4 | |
1 2 3 4 5 6 7 8 ; Indices | |
1 2 5 3 7 4 8 6 ; person-numbers | |
0 0 2 -1 2 -2 1 -2 ; person-numbers - indices | |
0 0 2 1 3 1 2 0 ; accumulated difference | |
; sum of accumulated difference: 9 | |
; Total bribery: 5 | |
1 2 3 4 5 6 7 8 ; Indices | |
1 2 5 3 7 8 4 6 ; person-numbers | |
0 0 2 -1 2 2 -3 -2 ; person-numbers - indices | |
0 0 2 1 3 5 2 0 ; accumulated difference | |
; sum of accumulated difference: 13 | |
; Total bribery: 6 | |
1 2 3 4 5 6 7 8 ; Indices | |
1 2 5 3 7 8 6 4 ; person-numbers | |
0 0 2 -1 2 2 -1 -4 ; person-numbers - indices | |
0 0 2 1 3 5 4 0 ; accumulated difference | |
; sum of accumulated difference: 15 | |
; Total bribery: 7 |
0 1 2 3 4 5 6 7 ; Indices
1 2 3 4 5 6 7 8 ; before change
1 2 5 3 7 8 6 4 ; person-numbers
; Total bribery: 7
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since the question only asks the number of bribes, there's no need to really do a sorting, nor element swapping, nor "bubbling up" an element. All you need to do is to count the number of people who overtake a person.