![]() |
VOOZH | about |
Given an array Arr which represent the percentage change. The task is to determine the Percentage increase after these percentage change. Examples:
Input: arr[] = {10, 20, 30, 10}
Output: Percentage change is = 88.76 %
Input: arr[] = {20, 15, 9, 7}
Output: Percentage change is = 60.94 %
Solution without successive change:-
let us take a number N = 120. and percentage changes are given as, arr[] = {10, 20, 30, 10} Now, if we first increase 120 by 10% i.e 120 * 1.1 We get N = 132 again if we increase it by 20% i.e 132 * 1.2 We get N = 158.4 again if we increase it by 30% i.e 158.4 * 1.3 We get N = 205.92 and lastly if we further increase it by 10% i.e 205.92 * 1.1 We get N = 226.51 Now, Percentage change = (226.51 - 120) / 120 = 0.8876 percentage change = 0.8876 * 100 = 88.76 %
👁 Image
How does this formula work? Let x be the initial value. After A% change, value of x becomes (x + x*A/100) After successive B% change, value of x becomes (x + x*A/100) + (x + x*A/100)*B/100. So increment in x's value is x*(A + B + A*B/100)/100. In terms of percentage, we can say that the value is incremented by (A + B + A*B/100)% Approach:-
Percentage change is = 88.76 %
Time complexity: O(N) where N is the size of the given array
Auxiliary space: O(1)