Java | Easy Solution | 100% | Maximum Two Possible Ways
Solution : Minimum(cost of all possible ways)\n\nMinimum Possible Ways : ONE(1) => minutes : seconds\nMaximum Possible Ways : TWO(2) => (1) minutes : seconds an
Solution : **Minimum(cost of all possible ways)**\n\nMinimum Possible Ways : ONE(1) => **minutes : seconds**\nMaximum Possible Ways : TWO(2) => (1) **minutes : seconds** and (2) **(minutes-1) : (seconds+60)**\n\n**Intuition behind maximum possible ways**:\n\nWays to write 99 seconds =>  01:39 and 00:99\nBut, 1:39 and :99 are also valid.\nSo, maximum possible ways comes to be FOUR(4).\n\nWait, If you carefully observer 01:39 and 1:39\nYou always find 1:39 as minimum solution, as extra ZEROs(0) will always add extra pushCost and moveCost.\n\nThus, we can neglect possible ways with prepending zeroes.\n\n\n\n\n```\nclass Solution {\n    public int minCostSetTime(int startAt, int moveCost, int pushCost, int targetSeconds) {\n    \n       //minutes\n       int min=targetSeconds/60;\n       //seconds\n       int sec=targetSeconds%60;\n            \n       int ans=Integer.MAX_VALUE;\n       Integer n=0;\n        \n        //Edge case: When minutes exceeds 99 \n        //e.g., targetSeconds=6008 => Only one possible way 99:68\n        if(min>99){ min=99; sec+=60; }\n            \n        //When rem <= 39, Two ways are possible : (1) min:rem (2) min-1:rem+60 \n        //e.g., targetSeconds=500 => (1) 8:20 (2) 7:80\n        if (sec <= 39) {\n            //calculating cost for (2) min-1:rem+60\n            Integer m=(min-1)*100+sec+60;\n            ans=Math.min(ans,cost(startAt,moveCost, pushCost,m.toString().toCharArray()));\n        }   \n        \n        //calculating cost for (1) min:rem\n        n=min*100+sec;\n        //finding minimun b/w (1) and (2), if (2) exists    \n        ans=Math.min(ans,cost(startAt,moveCost, pushCost, n.toString().toCharArray()));\n        \n        \n        return ans;\n    }\n    \n    //cost(1,2,1,{\'1\',\'0\',\'0\',\'0\'}) => returns 6\n    //cost(1,2,1,{\'9,\'6\',\'0\'}) =>returns 9\n    public int cost(int startAt,int moveCost, int pushCost, char num[]){\n        \n        int ans=pushCost*num.length;\n        \n        for(char c: num){\n            if(startAt!=c-\'0\'){\n                ans+=moveCost; \n                startAt=c-\'0\';\n            }\n        }\n        return ans;       \n    }\n}\n```
['Java']