We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
As others have also explained very well. It would be easy if we do it other way that is using Reduction.
Min(Elements) is 1. So min-1 and min-0 are 1 and 0.
Considering two cases:
i) Reducing it to 1:
1 --> 1 = 0 oper, 5 --> 1 = 2 oper and 5 --> 1 = 2 oper. Hence total 4 operations are required.
ii) Reducing it to 0:
1 --> 0 = 1 oper, 5 --> 0 = 1 oper and 5 --> 0 = 1 oper. total 3 operations are required.
Therefore min(4,3) we choose reducing it to 0 instead of 1. So answer is 3.
By the way, if you do it by Increasing, still 3 operations required, just follow this:
1- 1,5+1,5+1 -- 1,6,6
2- 1+5,6,6+5 -- 6,6,11
3- 6+5,6+5,11 -- 11,11,11
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Equal
You are viewing a single comment's thread. Return to all comments →
As others have also explained very well. It would be easy if we do it other way that is using Reduction. Min(Elements) is 1. So min-1 and min-0 are 1 and 0. Considering two cases: i) Reducing it to 1: 1 --> 1 = 0 oper, 5 --> 1 = 2 oper and 5 --> 1 = 2 oper. Hence total 4 operations are required. ii) Reducing it to 0: 1 --> 0 = 1 oper, 5 --> 0 = 1 oper and 5 --> 0 = 1 oper. total 3 operations are required.
Therefore min(4,3) we choose reducing it to 0 instead of 1. So answer is 3.
By the way, if you do it by Increasing, still 3 operations required, just follow this: 1- 1,5+1,5+1 -- 1,6,6 2- 1+5,6,6+5 -- 6,6,11 3- 6+5,6+5,11 -- 11,11,11