All cases Explained in depth. The best explanation you will come across.
Let us break it down into steps:\n1. step 1 convert the given input targetSeconds into minutes and seconds:\n\n2. step 2 generate all the permuatations for the 
Let us break it down into steps:\n1. step 1 convert the given input *targetSeconds* into minutes and seconds:\n![image](https://assets.leetcode.com/users/images/f0b69582-f37d-4861-956b-134ae3cb56dd_1645074224.8194745.png)\n2. step 2 generate all the permuatations for the input:\n* \tThere are some things we need to take care of\n* \tmin<=99 && sec<=99 as mentioned in the ques.\n* \tleading zeroes in minutes are of no use as they will just increase our cost as we would need an extra push and move (ex: 9min 60 sec ---> "9:60" and "09:60", the first is definetely better so no need for checking second one).\n* \tfor an input at most 2 unique permuations will be produced, as we can reduce 1min and add 60 to seconds. cant do it twice as sec<=99.\n3. Cases, when we produce string equivalent of a valid input\n* if(mins==0) we need no leading zeroes so we just put seconds into string\n* if(mins>0){\n\t\tif(secs==0) we need an extra zero to be added at last(9min 0 sec ---> "9:00")\n\t\tif(secs<10) we need extra zero before the second value(9min 6sec--->"9:06")\n\t\t}\n![image](https://assets.leetcode.com/users/images/18304ddf-16ff-4ad4-a52c-6b41c10ae31e_1645074863.678407.png)\n\n4. step 4. for each produced permuatation computing the cost.\n![image](https://assets.leetcode.com/users/images/9c577b75-b3b3-4504-a0be-9cf86c09dc8d_1645074955.522471.png)\n```\nclass Solution {\n    public int minCostSetTime(int startAt, int moveCost, int pushCost, int target) {\n        // step 1 convert targetSeconds to minutes\n        int min = target/60;\n        int sec = target%60;\n        \n        // step 2. go through the permutations\n        ArrayList<String> list = new ArrayList<String>();\n        // a input can have atmost 2 permutations\n        for(int i=0;i<2;i++)\n        {\n            // a input is valid only if min<=99 && sec<=99\n            if(min<100&&sec<100){\n            String mins = String.valueOf(min);\n            String secs = String.valueOf(sec);\n            if(min==0) list.add(new String(secs)); // we need no leading zeroes\n            else\n                {\n                    if(sec==0) // need a extra zero at end\n                    list.add(new String(mins+secs+"0"));\n                    else if(sec<10) // need a zero berfore second\n                    list.add(new String(mins+"0"+secs));\n                    else // everything is fine\n                    list.add(new String(mins+secs));\n                }\n            }\n            // second permuation is taking a minute out and adding it to seconds\n            min--;\n            sec+=60;\n        }\n        // System.out.println(list);\n        int res = Integer.MAX_VALUE;\n        // computing result\n        for(String str: list)\n        {\n            int cost = 0;\n            char prev = \'$\';\n            for(int i=0;i<str.length();i++)\n            {\n                char ch = str.charAt(i);\n                int chi = ch-\'0\';\n                // if first integer is same as startAt only pushCost is added\n                if(i==0&&chi==startAt)\n                {\n                    prev = ch;\n                    cost+=pushCost;\n                    continue;\n                }\n                // if curr is same as prev only pushcost is added\n                if(prev==ch)\n                {\n                     prev = ch;\n                    cost+=pushCost;\n                }\n                // if prev is not same moveCost and pushCost both are added\n                else\n                {\n                     prev = ch;\n                    cost+=pushCost+moveCost;\n                }\n            }\n            res = Math.min(res,cost);\n            // System.out.println(cost);\n        }\n        return res;\n    }\n}\n```\n
['Java']