0

Array Operations: Minimum Number of Operations.

You are given a number N. You also have a number K = 0.in one operation, you can add one number which is a power of two or three. You have to find the minimum number of operations required to make K equal to N. Note If it is not possible, then print -1. Sample : The given number is 15. In the first operation, we add 9 to K i.e. 9+0 = 9. In the second operation, we add 4 to Ki.e. 9+4= 13. In last operation, we add 2 to Ki.e. 13+2 = 15. Hence, the minimum number of operations required is 3.

27th Jul 2022, 8:25 PM
Sagar D Mudhale
1 Respuesta
+ 1
https://code.sololearn.com/c7RbaQ2MzC6W/?ref=app Do for I from 1 to K: if I is a root or square then f(i)=1 otherwise for all roots and squares less than I (rands) find min(i-rands). f(i)=that min + 1 It is dynamic programming, which is the brother of recursion.
28th Jul 2022, 9:22 AM
Oma Falk
Oma Falk - avatar