Day 33
Already done. Here to support π
thank you!!
Thank you so much Bhaiya ji πππ
tried implementing same solution in java, gives TLE. public class Solution { public List<Integer> lexicalOrder(int n) { List<Integer> ans = new ArrayList<>(); for (int i = 1; i <= n; i++) { solve(i, n, ans); } return ans; } private static void solve(int i, int n, List<Integer> ans) { if (i > n) { return; } if(ans.contains(i)) { return; } ans.add(i); for (int j = 0; j <= 9; j++) { int x = (i * 10) + j; if(x>n){ return; } solve(x, n, ans); } } }
Bhaiya please post today's POTD - Leetcode - 440 - K-th Smallest in Lexicographical Order
Bhaii bht accha explain kiya aapne thanks
didnt understand the space complexity
Hello MIK sir, here is the approach that I came up with, I think that this also takes the same time and space complexity, although could you please confirm? TC:O(n) SC:O(log10(n)) class Solution { public: void recur(int no, int n, vector<int>& arr) { if (no > n) return; for (int i = no; i < no + 10 && i <= n; i++) { if (i != 0) { arr.push_back(i); if (i * 10 <= n) { recur(i * 10, n, arr); } } } return; } vector<int> lexicalOrder(int n) { vector<int> arr; recur(0, n, arr); return arr; } }; ps: it took me 2 hours to come up with this approach :,)
aaj wala easy tha bhaiya. kuch mistakes karne k baad I was able to solve.
from where did you learn dsa?
Istπβ€
same code in java giving TLE.
can we solve it in O(1) space conplexity?
bhaiya make a video on meet in the middle algorithm
@AmandeepSingh-uq3wp