Java | min cost of (up to) 2 possible options, O(1)
Only up to 2 ways of setting the cooking time exist (ignoring those with explicitly pressed leading zeros) - just calculate their cost and pick the smallest.\n`
Only up to 2 ways of setting the cooking time exist (ignoring those with explicitly pressed leading zeros) - just calculate their cost and pick the smallest.\n```\nclass Solution {\n    public int minCostSetTime(int startAt, int moveCost, int pushCost, int targetSeconds) {\n        int ans= Integer.MAX_VALUE, mins= targetSeconds/60, secs= targetSeconds%60;\n        if(mins>0 && secs<40) // solution exists with >= 60 seconds\n            ans= cost(startAt, moveCost, pushCost, mins-1, secs+60);\n        if(mins<100) //solution exists with <60 seconds\n            ans= Math.min(ans, cost(startAt, moveCost, pushCost, mins, secs));\n        return ans;\n    }\n    \n    int cost(int startAt, int moveCost, int pushCost, int mins, int secs){\n        int i=0, ans= 0, dig[]= {mins/10, mins%10, secs/10, secs%10};\n        while(dig[i]==0) i++; // skip initial zeros\n        for(int curr= startAt; i<4; curr= dig[i++]) // calculate cost of digits\n            ans+= pushCost + (dig[i]!=curr ? moveCost : 0);\n        return ans;\n    }\n}
[]