You are the epitome of simplicity, thanks for the motivation and and for this goldmine disguised as video as well. THANKS AGAIN:)
aapki aawaz bht relaxing hai sir ๐ญ๐
Hi Mik, Thanks for putting up the editorials and explaination covering from brute to optimised approach, you're a gem.:face-red-heart-shape:
guruji mujhe esa feel hota hai ab potd ke videos banan apki duty hogai hai isse kabhi mt chhodna halanki har cheej hamesha to chalti nahi hai but fir bhii kuki ye ek esi duty hai jiske peeche hajaro bacche hai apke sahare se padh rhe hai question solve kr rhe hai or aage badh rhe hai mere mann ki baat thi mene bol di thanks ๐๐๐๐
Stack wala awesome solution hai. Maine backtracking se bhi banaya ise
Hi , I don't know who should be really reading it , But whoEver is reacting on Bhaiya's post with that sign on WhatsApp, "SHAME ON YOU" its been weeks i am seeing that reaction , And i Hate it everydayyyy, Today I am posting about it
You will become unstoppable, once you know that every setback is very much a reason for your greatest comeback
I reach pupil on codeforces thank you for your contribution bhaiya
Your second approach is absolutely brilliant! Iโm speechless
Stack approach is too good !!๐คฉ
Easily solve hogaya . Maine backtracking laga diya khandani template because constraint was very small. and Hats off to your dedication. take care MIK
Take a rest mik Its okiay U r so consistent taking break is good for health as well as for mental peace
Thank You ! loved your explanationโค
Did it using backtracking but here for the most optimal way.Thanks MIK bhaiya.
this problem's editorial is crazy.
class Solution { public: bool solve(int i, string &pattern, string &num, vector<bool> &used) { if (num.size() == pattern.size() + 1) return true; for (int j = 1; j <= 9; j++) { if (used[j]) continue; if ((pattern[i] == 'I' && num.back() - '0' < j) || (pattern[i] == 'D' && num.back() - '0' > j)) { num += to_string(j); used[j] = true; if (solve(i + 1, pattern, num, used)) return true; used[j] = false; num.pop_back(); } } return false; } string smallestNumber(string pattern) { vector<bool> used(10, false); for (int i = 1; i <= 9; i++) { string num = to_string(i); used[i] = true; if (solve(0, pattern, num, used)) return num; used[i] = false; } return ""; } };
First try mei run and accept hogya code. All thanks to the khandaani backtracking template ๐๐ช
class Solution { public: string smallestNumber(string pattern) { string result; stack<int> stk; // Iterate through the pattern and push elements to stack for (int i = 0; i <= pattern.size(); ++i) { stk.push(i + 1); // Push the next number // If it's an 'I' or end of pattern, pop all from stack if (i == pattern.size() || pattern[i] == 'I') { while (!stk.empty()) { result += to_string(stk.top()); stk.pop(); } } } return result; } };
thanks
@codestorywithMIK