Given an array of numbers, create a function that removes 25% from every number in the array except the smallest number, and adds the total amount removed to the smallest number.
We have a set of numbers, [4,1,4] and we need to remove the 25% of each number in that set.
first lets find the number which the smallest in the set.
To check whether the number is smallest number or not. For that, when we multiply 0.25 with any number if we should get a result less than 1 then it is called smallest number or else its a bigger number.
4 Then we calculate 25% for the bigger numbers, Example
lets take the first number 4 and then multiple it with 0.25 which gives us 1. then we need to subtract 1 out of 4 to get 3. Further we should replace 4 with 3.
To the Last, the smallest number for that we need to add the 25% of the rest of the numbers to the smallest number. Example [4,1,4]
new Smallest number = 25 % of 4 + smallest number + 25 % of 4
3 = 1+1+1
@Anishluke92 too technical and uses a specific example. Similar to my other comment in the other issue, rewrite algorithm to be without an example and no array used.
Check which number is the smallest in that set. Except that smallest number , we need to remove 25% of the remaining biggest numbers.
For that we take the first biggest number and remove the 25% of that number and the number is being updated. Similarly do that for all the remaining biggest numbers.
Now each 25% of the biggest numbers is added along with the smallest number and further the smallest is been updated.
Given an array of numbers, create a function that removes 25% from every number in the array except the smallest number, and adds the total amount removed to the smallest number.
Examples
Notes
There will only be one smallest number in a given array.