Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.56 KB | None | 0 0
  1. fun main(rating: Array<Int>): Int {
  2.     var total = 0
  3.     for (j in rating.indices) {
  4.         var smallerBeforeJ = 0
  5.         var biggerAfterJ = 0
  6.         var biggerBeforeJ = 0
  7.         var smallerAfterJ = 0
  8.         for (l in rating.indices) if (l != j) {
  9.             if (l < j && rating[l] < rating[j]) smallerBeforeJ++
  10.             else if (l > j && rating[l] > rating[j]) biggerAfterJ++
  11.             else if (l < j && rating[l] > rating[j]) biggerBeforeJ++
  12.             else if (l > j && rating[l] < rating[j]) smallerAfterJ++;
  13.         }
  14.         total += (smallerBeforeJ * biggerAfterJ) + (biggerBeforeJ * smallerAfterJ)
  15.     }
  16.     return total
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement