C++ | Beats 100% Time | Only 2 Cases for TargetScore | Easy to Understand
\n\nclass Solution {\npublic:\n    \n    \n    long long compute(int start, int move, int push, string target)\n    {\n        int len = target.size();\n       
\n```\nclass Solution {\npublic:\n    \n    \n    long long compute(int start, int move, int push, string target)\n    {\n        int len = target.size();\n        long long cost = 0;\n        int curr = start;  //keeps track of start point\n        \n        for(int i=0;i<len;i++)\n        {\n            int v1= target[i]-\'0\';\n            \n            if(curr==v1)\n            {\n                cost+= push;  //if the combination requires a digit at the current point, simply push it\n            }else{\n                cost+= move+push;  //otherwise, we move to the digit and push\n            }\n            curr=v1;\n        }\n        return cost;\n    }\n    int minCostSetTime(int startAt, int moveCost, int pushCost, int targetSeconds) {\n        \n\t\t//There will be two-cases for Target Score ~ (Minutes:Seconds) OR ((Minutes-1):Seconds)\n        int a = targetSeconds/60;\n        int b = targetSeconds%60;\n        \n        vector<string> pos;\n        \n        string fin = "";\n        \n        if(a>99 && b<=39)  //If this is the case, then we only have one possibility that is to have both in minutes\n        {\n            a--;\n            b+=60;\n            fin= to_string(a) + to_string(b);\n            pos.push_back(fin);\n        }else{\n\t\t\n\t\t\t//Case-1\n            if(a!=0){\n                fin = to_string(a);\n            }\n            string c = to_string(b);\n            \n            if(a!=0){                                //debug1\n                while(c.size()!=2)  //Prepending Zeros for seconds if minutes are not 0\n                {\n                    c = "0" + c;   \n                }\n            }\n            fin += c;\n            pos.push_back(fin);\n            \n            int save= (targetSeconds- ((a-1)*60));  //this is to check if save is less than 99 as seconds cannot be greater than 99\n            \n            if((a-1)>=0 && save>=0 && save<= 99)  //debug2: if save is within range, we have another possibility\n            {\n                fin = "";\n                if(a-1 !=0){\n                    fin = to_string(a-1);\n                }\n                b+= 60;\n                fin+= to_string(b);\n                pos.push_back(fin);\n            }\n        }\n        \n        long long ans= INT_MAX;\n        \n\t\t//Now, for every possibility, simply check the cost and find minimum\n        for(int i=0;i<pos.size();i++)\n        {\n            long long cost= compute(startAt, moveCost, pushCost, pos[i]);\n            if(cost<ans)\n            {\n                ans=cost;\n            }\n        }\n        return ans;\n        \n    }\n};\n```
['C', 'C++']