Remove K Digits | Remove K Digits LeetCode Solution Java | LeetCode 402

Sdílet
Vložit
  • čas přidán 7. 09. 2024
  • Remove K digits to make smallest number LeetCode Solution using Java Code. In this problem we have to Find the smallest number after removing k digits from the input number.
    Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible.
    LeetCode May Challenge PlayList - • First Bad Version | Fi...
    LeetCode April Challenge PlayList - • Move Zeroes LeetCode |...
    Note:
    The length of num is less than 10002 and will be ≥ k.
    The given num does not contain any leading zero.
    For example -
    Example 1:
    Input: num = "12345", k = 1
    Output: "1234"
    Explanation: Remove the digit 5 to form
    the new number 1234 which is the smallest.
    Example 2:
    Input: num = "1432219", k = 3
    Output: "1219"
    Explanation: Remove the three digits 4, 3, and 2 to form
    the new number 1219 which is the smallest.
    Example 3:
    Input: num = "10200", k = 1
    Output: "200"
    Explanation: Remove the leading 1 and the number is 200.
    Note that the output must not contain leading zeroes.
    Example 3:
    Input: num = "10", k = 2
    Output: "0"
    Explanation: Remove all the digits from the number and it is left with nothing which is 0.
    Website - webrewrite.com/
    Paypal - www.paypal.me/...

Komentáře • 16

  • @tacituskilgore2258
    @tacituskilgore2258 Před 4 lety +1

    Your channel is totally underrated, keep up the good work, my friend, your content is classy!

  • @bikramasingh1590
    @bikramasingh1590 Před 4 lety +1

    I must say this tutorial is simply amazing. Excellent work dude.

  • @UpYourHand
    @UpYourHand Před 5 měsíci

    Whoever is getting error just put this code at line no. 75
    while(k>0){
    st.pop();
    k--; }

  • @f3-faithfitnessfinance

    Amazing man!

  • @aadil4236
    @aadil4236 Před 2 lety

    What if we have an input like -> 1000000000000123. Then what?

  • @aakashchandwani293
    @aakashchandwani293 Před 4 lety

    Remove the REMAINING elements from stack thing , can you explain again. Not clear on that part

  • @saianushachodapaneedi7504

    upload source code..for checking my code once..im getting error

    • @ProgrammingTutorials1M
      @ProgrammingTutorials1M  Před 4 lety +1

      Sure, I'll do that. As i get the time i'll post the code on my website webrewrite.com/ and share the link. Meanwhile you can check other tutorials code here.

  • @PewarDesi
    @PewarDesi Před 4 lety

    This code is directly taken from Nick White..... Plz make your own Algo

    • @ProgrammingTutorials1M
      @ProgrammingTutorials1M  Před 4 lety +1

      Hi Sanjeev, It is not taken from there. This is the straight forward approach anybody can think for solving this problem.

    • @rubaborithm1911
      @rubaborithm1911 Před 3 lety

      ummm Nick white too have taken it from somewhere. There is basic rules that every one follow on these type of standard question.I have seen nick white code and one girl jayati tiwari.Both people show same code.Actually when you go to leetcode hint nah it throws same code.Just wrote because the channels main aim is to make people understand by any means .peace out.