Java Easy to Understand with Explanation O(1) time
Intuition - \nWe have only two choices:\n\nPunch minutes and seconds as is,\nor punch minutes - 1 and seconds + 60.\nWe just need to check that the number of mi
Intuition - \nWe have only two choices:\n\nPunch minutes and seconds as is,\nor punch minutes - 1 and seconds + 60.\nWe just need to check that the number of minutes and seconds is valid (positive and less than 99).\n\nFor example, for 6039 seconds, we can only use the second option (99:99), as the first option is invalid (100:39).\n\nso we create a method that takes minutes, seconds or minutes-1, seconds+60.\nto convert minutes and seconds to microwave time - microwaveTime = (minutes * 100) + seconds\ndigit - \'0\' to convert the char to integer\nif the current digit is same as our previous finger position, we don\'t need to move our finger again so move cost is 0. \n\ntime - O(1), space O(1)\n\n```\nclass Solution {\n    public int minCostSetTime(int startAt, int moveCost, int pushCost, int targetSeconds) {\n        \n        int minutes = targetSeconds/60;\n        int seconds = targetSeconds%60;\n        \n        return Math.min(getCost(startAt, minutes, seconds, moveCost, pushCost), getCost(startAt, minutes-1, seconds+60, moveCost, pushCost));\n    }\n    \n    public int getCost(int startAt, int minutes, int seconds, int moveCost, int pushCost) {\n        \n        if(Math.min(minutes, seconds) < 0  || Math.max(minutes, seconds) > 99) return Integer.MAX_VALUE;\n        \n        int minCost = 0;\n        \n        int microwaveTime = (minutes * 100) + seconds;\n        char[] digits = String.valueOf(microwaveTime).toCharArray();\n        \n        for(char digit : digits) {\n        \n    //  digit - \'0\' to convert the char to integer\n            int digitInteger = digit - \'0\';\n            \n    // if the current digit is same as our previous finger position, we don\'t need to move our finger again so move cost is 0. \n            minCost = minCost + pushCost + (startAt == digitInteger ? 0 : moveCost);\n            \n            // assigning the startAt position as the previous position.\n            startAt = digitInteger;\n        }\n        return minCost;\n    }\n}
['Java']