fork download
  1. class Solution {
  2. public static int countPairs(int arr[], int n)
  3. {
  4. // Your code goes here
  5. int a[]=new int[n];
  6. int count=0;
  7.  
  8. for(int i=0; i<n; i++)
  9. {
  10. a[i]=i*arr[i];
  11. }
  12. for(int i=0; i<n; i++)
  13. {
  14. for(int j=i+1; j<n; j++)
  15. {
  16. if(a[i]>a[j])
  17. count++;
  18. }
  19. }
  20.  
  21. return count;
  22. }
  23. public static void main(String[]args)
  24. {
  25. int arr[]={8,4,2,1};
  26. int n=4;
  27. System.out.println(countPairs(arr, n));
  28. }
  29. }
Success #stdin #stdout 0.11s 54648KB
stdin
Standard input is empty
stdout
2