11 N Digit numbers with digits in increasing order

Sdílet
Vložit
  • čas přidán 7. 09. 2024
  • Given an integer N, print all the N digit numbers in increasing order, such that their digits are in strictly increasing order(from left to right).
    Example 1:
    Input:
    N = 1
    Output:
    0 1 2 3 4 5 6 7 8 9
    Explanation:
    Single digit numbers are considered to be
    strictly increasing order.
    ------------------------------------------------------------------------------------------
    Here are some of the gears that I use almost everyday:
    🖊️ : My Pen (Used in videos too): amzn.to/38fKSM1
    👨🏻‍💻 : My Apple Macbook pro: amzn.to/3w8iZh6
    💻 : My gaming laptop: amzn.to/3yjcn23
    📱 : My Ipad: amzn.to/39yEMGS
    ✏️ : My Apple Pencil: amzn.to/3kMnKYf
    🎧 : My Headphones: amzn.to/3kMOzM7
    💺 : My Chair: amzn.to/385weqR
    🛋 : My Table: amzn.to/3TyU2IU
    ⏰ : My Clock: amzn.to/3slFUV3
    🙋🏻‍♀️ : My girlfriend: amzn.to/3M6zLDK ¯\_(ツ)_/¯
    PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.

Komentáře • 43

  • @riteshranjan1262
    @riteshranjan1262 Před 7 měsíci +14

    Bhaiya please complete the DP playlist 🙏

  • @jatinverma7234
    @jatinverma7234 Před 7 měsíci +1

    I was watching the playlist and was just worried that why 1 video is hidden but as i reached upto this video it was available thanks. waiting for more.

  • @techsavy5669
    @techsavy5669 Před 3 měsíci +1

    Why back tracking needed here!! Clean and simple.
    void Digits(String s, integer start, integer n, Array List list)
    {
    if (n== 0)
    list add your s (after parsing them into an integer object directly.)
    return;
    }
    for loop X from 1 to 9
    Digits (s + X, X+1, n - 1 , list)
    }

  • @abhishekparmar7135
    @abhishekparmar7135 Před 6 měsíci +4

    we could have taken a string instead of a vector so that we change and remove the characters at ease , below is my approach
    void solve(int idx,string &str,int k,vector &res){
    //base case
    if(str.size()==k){
    res.push_back(stoi(str));
    return ;
    }
    for(int j=idx+1;j

    • @4mulate
      @4mulate Před 12 dny

      i did the same just pehla n=1 mei 0 nahi aaraha tha wahi bas yeh bhi ez hai

  • @muskanmadhwani2934
    @muskanmadhwani2934 Před 6 měsíci

    You are the best Instructor of DSA on CZcams. I have watched all your playlists. Please make Trees playlist. PLEASEEEEEE.

  • @yashkumar-re3by
    @yashkumar-re3by Před 4 měsíci +2

    I am very grateful to you for your videos. But the solution in this video is a bit unoptimized. We dont need a vector to store digits of the number. here is a solution
    void solve(int &num, int remainingDigits, vector &ans){
    if(remainingDigits == 0){
    ans.push_back(num);
    return;
    }
    int largestDigit = num%10;
    //largest digit is the last digit
    num *= 10;
    for(int i=largestDigit+1; i

    • @karankansykar9273
      @karankansykar9273 Před 3 měsíci +1

      You are right!!

    • @kanganabhargava1273
      @kanganabhargava1273 Před 3 měsíci +1

      What's need of n=n/10. It is working fine without it also.

    • @yashkumar-re3by
      @yashkumar-re3by Před 2 měsíci

      @@kanganabhargava1273 I am assuming you meant the code is running without num = num/10. If you look closely, in the solve function, I am passing num as pass by reference (for space optimization). It will work without num=num/10 if you use int num as pass-by-value in the solve method.
      Hope this helps !

  • @ApaarBawa-xx1to
    @ApaarBawa-xx1to Před 5 měsíci

    python code:
    # Time Complexity: 9^n
    def increasingNumber(n):
    res = []
    # handle n = 1 case explicitely
    if n == 1:
    res = [i for i in range(10)]
    return res
    vec = []
    def solve(vec, res, n):
    # base condition
    if n == 0:
    # combine vec and append to res
    ans = 0
    for i in range(len(vec)):
    ans = (ans * 10) + vec[i]
    res.append(ans)
    return
    # iterate over choices
    for i in range(1, 10):
    # controlled recursion
    if len(vec) == 0 or i > vec[-1]:
    vec.append(i)
    # recursion call
    solve(vec, res, n-1)
    # backtrack
    vec.pop()
    solve(vec, res, n)
    return res
    Thanks for the explanation Aditya!

  • @sambhavjain3653
    @sambhavjain3653 Před 13 dny

    bro even if the video is long it works, or break it in 2 parts as you have been doing before, I would request you to keep teaching time complexity for few more videos and then after some of the questions you can leave it on us

  • @NextLevelShit
    @NextLevelShit Před 7 měsíci

    Same here i just opened to complete the heap series and saw new video uploaded , happy to see you back bhaiya , keep up the good work. love you bhai dheeer sara

  • @deepanshuverma6237
    @deepanshuverma6237 Před 2 měsíci

    Java Solution :
    Using String hence backtrack wouldn't matter:
    public static void main(String[] args) {
    int N = 5;
    String op = "";
    digits(N, op);
    }
    private static void digits(int n, String op) {
    if (op.length() == n) {
    System.out.println(op);
    return;
    }
    if (op.isEmpty()) {
    for (int i = 0; i

  • @prateek4279
    @prateek4279 Před 6 měsíci +2

    did this question by myself without seeing the vid

  • @shankysays
    @shankysays Před 6 měsíci +1

    hey i have a request. in dp playlist you never made any video on longest increasing subsequence type problems. please make some videos on this pattern and how to approach this pattern please. humble request... :)

  • @shreyxnsh.14
    @shreyxnsh.14 Před měsícem

    a solution using a different approach (strings instead of vector)
    class Solution {
    public:
    void solve(int curr, int n, string &str, vector &res){
    if(str.size() == n){
    res.push_back(str);
    return;
    }
    for(char c='1'; c str[curr-1]){
    str+=c;
    solve(curr+1, n, str, res);
    str.pop_back();
    }
    }
    }
    vector increasingNumbers(int n) {
    // Write Your Code here
    vector ans;
    if(n==1){
    for(int i=0;i

  • @ashutoshsingh7537
    @ashutoshsingh7537 Před 7 měsíci

    Abhi isiliye channel khola tha ki bhai ko comment karte hai ki series puri kre, aur bhai ne nyi video upload kardi😊

  • @vibhumkaila8000
    @vibhumkaila8000 Před 6 měsíci

    Can you please tell names of questions for the DP patterns you have not covered in your playlist but discussed in the first video like Fibonacci(7 questions) LIS(10 questions) Kadane's (6 questions) DP on grid(14) others(3)

  • @souviksen5177
    @souviksen5177 Před 2 měsíci

    Java Solution:
    class Solution {
    static ArrayList list;
    public static ArrayList increasingNumbers(int n) {
    list = new ArrayList();
    ArrayList temp = new ArrayList();
    if(n == 1){
    for(int i=0; i

  • @user-xn2jv2cj1h
    @user-xn2jv2cj1h Před 6 měsíci +1

    bhaiya after this start trees thank you

  • @nilesh6439
    @nilesh6439 Před 6 měsíci

    Bhiaya sorry par mujhe aapka channel hindi me best explanation wala laga ,aur mere may be may ke baad se company aana start ho jayengi par oncapmus ke liye mujhe arrays aur strings ki series ki requirement thi , umeed aaapse hi kar rha hu please , request hai

  • @mohit6215
    @mohit6215 Před 6 měsíci +1

    King is back 😎

  • @kartikkalra9353
    @kartikkalra9353 Před 7 měsíci +1

    Agaya bhai dubara ❤

  • @biswajeetmuduli
    @biswajeetmuduli Před 7 měsíci

    Holy f mujhai laga bhai tapak gaya😢....Glad you're doing good 😊👍

  • @Prateek_Mantry
    @Prateek_Mantry Před 4 měsíci +1

    baaki videos v bana do bhaiya 🥺. thank you.

  • @saurabhtrigunayat4071
    @saurabhtrigunayat4071 Před 7 měsíci

    Finally, bro, came back🤩❤.

  • @anjukushwaha5808
    @anjukushwaha5808 Před 7 měsíci

    Bhaiya after this playlist will you upload video on a topic tree.??

  • @sahebraojadhav9727
    @sahebraojadhav9727 Před 7 měsíci +1

    Bhai please complete dp

  • @PiyushCodes-ph3hl
    @PiyushCodes-ph3hl Před 7 měsíci

    Bhaiya aap DP series complete karwa do please
    and baki topics bhi le aao
    also if possible then striver bhaiya wali sheet types patterns match kar sakte ho toh best not telling to copy but

  • @Itachi-kw5cs
    @Itachi-kw5cs Před 7 měsíci

    Thank you brother

  • @codecreateriitp4751
    @codecreateriitp4751 Před 7 měsíci

    bhaiya yar thoda graph bhi padha do esake bad please and please take cses problem set graph question

  • @suraj_patwa
    @suraj_patwa Před 7 měsíci +1

    Welcome Again

  • @_desouvik
    @_desouvik Před 4 měsíci

    "9!" hoga na time complexity?

  • @kannan.m9274
    @kannan.m9274 Před 6 měsíci

    Sir pls kindly add subtitles in dp playlist sir pls sir

  • @gauravbanerjee2898
    @gauravbanerjee2898 Před 7 měsíci

    love u 3000 bhaiya ❤❤

  • @saksham_1612
    @saksham_1612 Před 7 měsíci

    Bhai poori kardo please yarr ❤❤

  • @NextLevelShit
    @NextLevelShit Před 7 měsíci +1

    133 view but itne kam like ?

  • @kaushikramabhotla4635
    @kaushikramabhotla4635 Před 7 měsíci +1

    Bhai 🤩

  • @kullumanali-bu8uf
    @kullumanali-bu8uf Před 7 měsíci

    the real slim shady

  • @rishavraj9284
    @rishavraj9284 Před 7 měsíci

  • @AnkeshKumar-fx4dl
    @AnkeshKumar-fx4dl Před 7 měsíci +1

    Bro❤❤❤