Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun main(rating: Array<Int>): Int {
- var total = 0
- for (j in rating.indices) {
- var smallerBeforeJ = 0
- var biggerAfterJ = 0
- var biggerBeforeJ = 0
- var smallerAfterJ = 0
- for (l in rating.indices) if (l != j) {
- if (l < j && rating[l] < rating[j]) smallerBeforeJ++
- else if (l > j && rating[l] > rating[j]) biggerAfterJ++
- else if (l < j && rating[l] > rating[j]) biggerBeforeJ++
- else if (l > j && rating[l] < rating[j]) smallerAfterJ++;
- }
- total += (smallerBeforeJ * biggerAfterJ) + (biggerBeforeJ * smallerAfterJ)
- }
- return total
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement