fork download
  1. //
  2. // main.cpp
  3. // Number of moves
  4. //
  5. // Created by Himanshu on 19/09/21.
  6. //
  7.  
  8.  
  9. #include <iostream>
  10. #include <vector>
  11. #include <climits>
  12. using namespace std;
  13. #define MAX 100
  14.  
  15.  
  16. int solve (vector<int> nums) {
  17. int sum = 0, minElement = INT_MAX, n = (int) nums.size();
  18. for (int i=0; i<n; i++) {
  19. minElement = min(minElement, nums[i]);
  20. sum += nums[i];
  21. }
  22.  
  23. return (sum - (n*minElement));
  24. }
  25.  
  26. int main(int argc, const char * argv[]) {
  27. vector<int> nums = {1, 2, 3};
  28. printf("Number of moves to equalise array elements: %d\n", solve( nums));
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5464KB
stdin
Standard input is empty
stdout
Number of moves to equalise array elements: 3