@AmandeepSingh-uq3wp

I also wrote the same code but still comes here to expand my knowledge from mik sir.

@ManaswiRane

Day 33

@hypewaali

Already done. Here to support 😊

@rishithp3077

thank you!!

@rockykumarverma980

Thank you so much Bhaiya ji πŸ™πŸ™πŸ™

@manasdeora4601

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);
        }
    }
}

@gui-codes

Bhaiya please post today's POTD - Leetcode - 440 - K-th Smallest in Lexicographical Order

@AdarshSingh-cd8qt

Bhaii bht accha explain kiya aapne thanks

@dibbodas4116

didnt understand the space complexity

@shivanshplays9218

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 :,)

@gui-codes

aaj wala easy tha bhaiya. kuch mistakes karne k baad I was able to solve.

@prathmeshkakde3731

from where did you learn dsa?

@dayashankarlakhotia4943

IstπŸŽ‰β€

@princeberi4501

same code in java giving TLE.

@kancharlasrimannarayana7068

can we solve it in O(1) space conplexity?

@AlexKumarI-c6d

bhaiya make a video on meet in the middle  algorithm