Minimum steps to destination - GFG POTD Solution in Just 10 Minutes!

preview_player
Показать описание
This is GFG POTD (Problem of the day) Solution for the gfg problem - Minimum steps to destination with detailed explanation video of the approach and the code.

Hope you found this video helpful!

Telegram Link where I will be posting the solutions daily:

Don't worry you will get the solutions everyday here, so just comment, like and subscribe !!
Рекомендации по теме
Комментарии
Автор

i tried and some of the test cases passed in starting as when d=10 and 15 but sometime it failed

class Solution {
public:
int countStep(int dest, int pos, int count, int &steps) {
if (dest == pos) {
return count;
}
count++;
steps++;
pos += count;
if (pos > dest) {
pos -= steps;
}
return countStep(dest, pos, count, steps);
}

int minSteps(int d) {
int steps = 0;
int minStep = countStep(d, 0, 0, steps);
return minStep;
}
};

i_sumit