[Java] Detailed explanation with example
METHOD IS TO CONVERT ALL NUMBERS TO THE MEAN OF THE ARRAY\nlet n=5(IT\'S NOTHING BUT AN ARRAY OF N CONSECUTIVE ODD INTEGERS)\nthen array[1,3,5,7,9], mean is (1+
**METHOD IS TO CONVERT ALL NUMBERS TO THE MEAN OF THE ARRAY**\nlet n=5(IT\'S NOTHING BUT AN ARRAY OF N CONSECUTIVE ODD INTEGERS)\nthen array[1,3,5,7,9], mean is (1+9)/2=5\nthen the best method to minimize the conversion steps will be to convert all numbers to array mean (1+9)/2=5\nsince \nNumber of. operations to convert 1 and 9 to 5 is= 4 steps\nNumber of. operations to convert 3 and 7 to 5 is= 2 steps\nNumber of. operations to convert 5 to 5 is= 0 steps\nhence 4+2+0=6 is answer\n**CONCLUSION- number of steps to convert the first half==number of steps to convert second half**\n**SO WE JUST NEED TO FIND STEPS FOR THE FIRST HALF**\n**NOTE- MEAN OF N CONSECUTIVE ODD INTEGERS IS N**\n```\nclass Solution {\n    public int minOperations(int n) {\n        if(n==0 || n==1)\n            return 0;\n        int count=0;\n        for(int i=0;i<n/2;i++)// for the first half\n        {\n            count+=(n-(2*i+1));// mean will always be \'n\' reason given in the note above (try yourself)\n        }\n        return count;\n    }\n}\n```
[]