Easy to understand || Well Explained || Dfs || Clean Code || Complexity-Analysis
Just do as question said :\nStart from 0 : \n1. And if you\'re currently at the button which has previously pressed or it\'s the begginging then you\'ll spend j
Just do as question said :\nStart from 0 : \n1. And if you\'re currently at the button which has previously pressed or it\'s the begginging then you\'ll spend just only pressCost.\n2. Else, you need to move first you\'re desire button(moveCost) and than you need to press it(pressCost). I.e. moveCost+pressCost.\n3. Now, In recursion if you moved from a button to a new button than you must update the lastPressedButton also so that you wouldn\'t need to invest move cost again.\n4. Find the min from all the possibilites.\n\nNow you need handle those cases who are not incrementing in terms of number \ne.g. 000 you can add one more 0 i.e. 0000 but it is still 0. \nSo to handle this you can use how many times you have pushed the number and atmost you can push 4 times because \nmicrowave supports cooking times for:\n* at least 1 second.\n* at most 99 minutes and 99 seconds.\n```\nclass Solution {\npublic:\n    bool isEqual(int source, int target) {\n    \n      // Convert source to sec\n      int min = source/100;\n      int sec = source%100;\n      return (min*60+sec) == target;\n    }\n\n\tlong solve(int curr, int moveCost, int pressCost, int target, int lastPressedButton, int times=0) {\n        \n        // Handle Overflow conditions\n        if(curr>9999 || times>4) {\n            return INT_MAX;\n        }\n\n        // If we get target than no need to do anything\n        if(isEqual(curr,target)) {\n            return 0;\n        }\n\n        long res=INT_MAX;\n        \n        // Now start from 0-th button and keep pressing one by one\n        for(int i=0;i<10;i++) {\n            long ans = (pressCost+(i!=lastPressedButton)*moveCost) + solve(curr*10+i, moveCost, pressCost, target, i, times+1);\n            res = min(res,ans);\n        }\n        return res;\n    }\n\n\tint minCostSetTime(int start, int moveCost, int pressCost, int target) {\n\t\treturn solve(0, moveCost, pressCost, target, start);\n\t}\n};\n```\n\n# Time Complexity : \nSo we\'re are pressing for each button for every move.\nSo atmost there can be 4 move i.e. <9999  or log(1e5)base10\nAnd for one move cost will be 10.\nSo for 4 move cost will be 10^4.\nSo more formally in the worst case (10^ log(1e5)base10).\n\n# Space Complexity :\nSo we are not using any extra space except recursion stack.\nSo at any point time what will be the maximum number of function which would have been pushed?\n1. Since, Each step we are incrementing by one digit or pushing one button.\n2. So at worst case I have been pushed all the button(atmost 4 button).\n\nSo overall stack size would be atmost of 4 i.e. constant.\n\n**Feel free to correct me if I was wrong any where. And please upvote if you find it usefull.\nHappy Coding!**
['C']