C++ || MIN-MAX logic, O(1) Time Complexity Solution and O(1) Space.100% faster
Logic is explained in code, we need to check minimum minute that can be possible and maximum minute that can be possible.\n\n\n int cal(int minute, int second, 
Logic is explained in code, we need to check minimum minute that can be possible and maximum minute that can be possible.\n\n```\n int cal(int minute, int second, int pc, int mc, int sa) {\n  int cost = 0;\n\n  // m2 represent second digit of minute, m1 represent first digit of minute\n  int m2 = minute % 10;\n  minute /= 10;\n  int m1 = minute % 10;\n\n// s2 represent second digit of minute, s1 represent first digit of minute\n  int s2 = second % 10;\n  second /= 10;\n  int s1 = second % 10;\n\n/* check if first digit of minute is >0 ,\n  if no, then we don\'t type \'0\' because it will auto normalize, \n  if Yes, then check whether start at is same as first digit(m1),\n      if no, then increment cost by move cost+push cost\n      if yes, then increment cost by push cost\n      set start at to m1\n*/ \n  if (m1 > 0) {\n    if (sa != m1) {\n      cost += pc + mc;\n    } else {\n      cost += pc;\n    }\n    sa = m1;\n  }\n  \n/* check if second digit of minute is >0 or we have typed first digit m1 of minute (then cost>0) ,\n  if no, then we don\'t type \'0\' because it will auto normalize, \n  if Yes, then check whether start at is same as second digit(m2),\n      if no, then increment cost by move cost+push cost\n      if yes, then increment cost by push cost\n      set start at to m2\n*/\n  if (m2 > 0 || cost > 0) {\n    if (sa != m2) {\n      cost += pc + mc;\n    } else {\n      cost += pc;\n    }\n    sa = m2;\n  }\n\n  /*Just like minute we also need to check whether we need to type s1 and s2 , if we already typed previous digit (that means cost>0)\n  then we have no choice except typing s1 and s2, else if cost==0 that means m1=0,m2=0, so if s1=0 then we don\'t type s1 else we need to type \n  it . At the end we always have to type s2 because there can always be second for example 00:01, 00:55.let take 00:00 ,even if we start at 0\n  then also without pushing(typing) 0 it cannot normalize to 00:00 so, we have to push last digit of second ie s2 */\n  if (s1 > 0 || cost > 0) {\n    if (sa != s1) {\n      cost += pc + mc;\n    } else {\n      cost += pc;\n    }\n    sa = s1;\n  }\n\n  if (sa != s2) {\n    cost += pc + mc;\n  } else {\n    cost += pc;\n  }\n  sa = s2;\n\n  return cost;\n}\nint minCostSetTime(int startAt, int moveCost, int pushCost, int targetSeconds) {\n  // Lmin denote minimum minute that we can set to form given tarrget Second\n  int lmin = 0;\n  if (targetSeconds > 99) lmin = ceil((1.0 * (targetSeconds - 99)) / 60);\n\n  //Rmin denote maximum minute that we can set to form  given target Second \n  int rmin = targetSeconds / 60;\n  rmin = min(99, rmin);\n\n\n  // Taking Minute from lmin to rmin and computing Second required to form Target Second And Then finding operation needed\n  int ans = INT_MAX;\n  for (int i = lmin; i <= rmin; i++) {\n    int sec = targetSeconds - i * 60;\n    int op = cal(i, sec, pushCost, moveCost, startAt);\n    ans = min(op, ans);\n  }\n  return ans;\n}\n```\n\nTime Complexity: O(1)\nminimum minute always be ceil(1.0*targetSeconds-99)/60)\nmaximum minute always be floor(targetSeconds/60)\n\ndifference in between always be <=2 so loop will always for loop run 2times,\nnow each loop iteration call cal function which calculate operation needed that is basically O(1)\n\nSpace Complexity: O(1) because no extra space used
['Math', 'C', 'C++']