Convert Integer to Roman numeral - LeetCode Interview Coding Challenge [Java Brains]

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ส.ค. 2024
  • Interview Question: Convert Integer to Roman numeral
    Leetcode link: leetcode.com/p...
    Solution Gist: gist.github.co...
    Difficulty level: Easy
    Language: Java
    Welcome to the Java Brains Java Interview challenge series of videos where we tackle various coding challenges ranging from the beginner level to advanced level - especially in the context of coding interviews.
    Any coding problems you would like me to explore? Please let me know in the comments what you think!
    #java #interview #javabrains

ความคิดเห็น • 75

  • @rutvij2811
    @rutvij2811 4 ปีที่แล้ว +11

    As you have said in the end, sometimes we complicate fairly simple tasks. I was thinking about using switch case , hashmap and whatnot before I saw your approach to the question. Amazing explanation.

    • @elainelopes7043
      @elainelopes7043 2 ปีที่แล้ว

      Zvgdbdgsbshdbhysdhvxgdgebebsyydhnxnxnhybxsbsnh hj d vc TB hj

    • @elainelopes7043
      @elainelopes7043 2 ปีที่แล้ว

      Bvgz gsbhggbevgrhvfgggstztyyggf
      Gv
      Nnjbdbsbshs7dududuuddduydyydydd7yhyxyyddhhdd6hhhshdyhvhdhnjfbhhghhfgedbzgfbdehhdhejbznzhshsjsshbjnshbzb um yt

    • @SatyamKumar-bw4vi
      @SatyamKumar-bw4vi 2 ปีที่แล้ว

      same with me

  • @suseelkumarannamraju
    @suseelkumarannamraju 3 ปีที่แล้ว +1

    After so many days, I recollected my childhood days, where I use to play with Roman numbers, but completely forget when days have grown. Now it's because of u, I recollected them and felt enjoying by looking at your video. Thank you so much sir.

  • @ADGroupOfArtMedia1
    @ADGroupOfArtMedia1 4 ปีที่แล้ว +5

    Yeeee! I love you Man! Thanks a ton for every contribution you made in my career!

  • @vinayprasad4659
    @vinayprasad4659 4 ปีที่แล้ว +20

    Wow. I did not know you started sharing leetcode questions. This is awesome. Is there a playlist?

    • @Java.Brains
      @Java.Brains  4 ปีที่แล้ว +16

      Thanks! Here you go: th-cam.com/play/PLqq-6Pq4lTTZgXnsBNQwCWdKR6O6Cgk1Z.html
      Not a lot yet, but there will be more coming up. Make sure you are subscribed with notifications if you don't want to miss out! :)

    • @vinayprasad4659
      @vinayprasad4659 4 ปีที่แล้ว +1

      This is super awesome Koushik. Thanks for sharing. Your videos have helped me for years. You make extremely complicated things very simple. I will keep looking for this space.

  • @abhinav9469
    @abhinav9469 4 ปีที่แล้ว +4

    Thanks for sharing this gem. If I had not gone through this video I would have chosen a much complex approach to solve this. This solution teaches that for some 'COMPLEX-SOUNDING' problems. A simple and feasible solution exists. All we need is to stick to the basics...
    Thanks again for this wonderful tutorial Kaushik..God bless you.

  • @geovanny_alfaro
    @geovanny_alfaro 4 ปีที่แล้ว +6

    This is such a great video, I remember the first time I encountered it in school. I went a different more convoluted route.

  • @kirant5548
    @kirant5548 2 ปีที่แล้ว

    One of the best optimised solution for int to roman conversion. your just awesome man

  • @sureshgarine
    @sureshgarine 3 ปีที่แล้ว +1

    wow! what a nice thinking process. many TH-camrs share logic, but to my surprise, you speak about the thought process. Thank you so much sir. can you please make leetcode playlist for all the medium level problems

  • @tanaypatel8412
    @tanaypatel8412 ปีที่แล้ว

    Saiman says teaching java, amazing...

  • @shrad6611
    @shrad6611 2 ปีที่แล้ว

    thumbs up :), and sorry for prev comment on last video

  • @vocipy2068
    @vocipy2068 ปีที่แล้ว

    When Roman Numerals were invented, there was no concept of Zero, and nobody had yet thought about negative numbers as a concept.

  • @FBHI
    @FBHI 10 หลายเดือนก่อน

    And here I was so proud of my code:
    "int unit = value % 10;
    value /= 10;
    int dozen = value % 10;
    value /= 10;
    int cent = value %10;
    value /= 10;
    int mil = value %10;
    value /= 10;

    return thousands[mil]+hundreds[cent]+tens[dozen]+units[unit];"
    Lot of repeated stuff honest work, then I saw the video results..... sooo much to learn =/

  • @monsterhuntergo
    @monsterhuntergo ปีที่แล้ว

    Amazing! my Primary-2 kid actually have this Math topic of ones, tens, and hundreds.. This is an amazing solution. Thanks so much sensei Kaushik. :)

  • @preethialbert9652
    @preethialbert9652 4 ปีที่แล้ว

    Please do more of these type of problems. Your explanation is very good and clear. Expecting more like this

  • @hunterlive2434
    @hunterlive2434 3 ปีที่แล้ว

    Greetings from Russia. Thanks!

  • @madhug82
    @madhug82 3 ปีที่แล้ว

    super one Kaushik. the approach you take to these problems is very intuitive . Thanks for this video.

  • @aleksapetrovic6519
    @aleksapetrovic6519 ปีที่แล้ว

    Interesting. I tought we would need to do the parse at one point. This is an excellent solution.

  • @shuchivarshney3191
    @shuchivarshney3191 3 ปีที่แล้ว

    @Java Brains - Super Awesome..!! I like the "what kind of questions you can ask from Interviewer" part of your video, this usually youtuber don't tell it. Please go ahead with Leetcode series.

  • @cdhagen
    @cdhagen 4 ปีที่แล้ว

    Your videos keep getting better and better. Kudos!

  • @bhaminisundararaman6080
    @bhaminisundararaman6080 2 ปีที่แล้ว

    wow...my solution was....quite....extensive.....
    thank you for this lol

  • @metamike_23
    @metamike_23 ปีที่แล้ว

    I just answered this question on leetcode and it took me 95 lines of code to get a solution

  • @OzWannabe
    @OzWannabe 4 ปีที่แล้ว +1

    This will work up to 3000. You can make it work easy up to 10000 or to max_value from short (just don't pass int as argument as this can go from -2147483647 to +2147483647to . What Romans did was to add a line over a number meaning they were multiplying that number by 1000. So, if you needed to write 9000 you had IX with a line over it. So for a max short (32768) you would have the tens of thousands XXX with a line over it and then use your function to append to it.

  • @nerodant85
    @nerodant85 2 ปีที่แล้ว

    Thank you so much for making the question so easy to understand

  • @VinitKumar_Vinigem
    @VinitKumar_Vinigem 4 ปีที่แล้ว +2

    Thanks for sharing these.

  • @ashvajitchauhan608
    @ashvajitchauhan608 4 ปีที่แล้ว +2

    Very helpful, It would be appreciable if you make video on cache mechanism in spring and software perform. Thanks in advance

  • @Impromptu21
    @Impromptu21 3 ปีที่แล้ว

    Nyc one sir

  • @SaurabhkrGupta-tc7qs
    @SaurabhkrGupta-tc7qs 3 ปีที่แล้ว

    Thanks for the great explaination Kaushik. Kudos to you

  • @NareshKumar-dw9xp
    @NareshKumar-dw9xp 4 ปีที่แล้ว

    Why do I have a fear while watching your video like you are my interviewer and I am the student ? LOL :)
    Videos are always awesome btw

  • @dance_with_shivangi.
    @dance_with_shivangi. 4 ปีที่แล้ว +1

    Your voice is like sundar pichai

  • @kbhargavi4400
    @kbhargavi4400 3 ปีที่แล้ว

    Amazing sir!! Truly most clear explanation! : )

  • @meeknkosi
    @meeknkosi 3 ปีที่แล้ว

    you explain so perfectly

  • @namratam1522
    @namratam1522 4 ปีที่แล้ว

    Please try uploading more and more algorithmic questions where getting logic is difficult. Example: sliding window alogos etc.

  • @raman2192
    @raman2192 4 ปีที่แล้ว

    Nice one

  • @shubhamsaurabh4419
    @shubhamsaurabh4419 4 ปีที่แล้ว

    Thanks you so much sir!!! This solution is amazing!!! Wonderful!!!
    Maja aa gaya. In the beginning i thought that this is a very tough question but the way you solve it and the solution is no doubt amazing!!! Thanks once again sir...

  • @krishanuchakraborty3500
    @krishanuchakraborty3500 4 ปีที่แล้ว

    Thanks a ton for this video, I love the way you explain the concepts, would request you to add more such unique Java Interview question videos to this series. Thanks.

  • @tarmagoyf95
    @tarmagoyf95 4 ปีที่แล้ว +1

    Hi, romans didn't have the concept of negative numbers, the only use natural numbers without the 0 number

  • @MaheshBabu-ys3vh
    @MaheshBabu-ys3vh 3 ปีที่แล้ว

    Hi Koushik, First of all, thank you for all your lectures. Your video quality is excellent. Would you like to put list of resources you use for the video making? It will help a lot for starters like me who interested to start a youtube channel. Tools like what whiteboard app you are using, are you using apple pencil etc. Also if you have any affiliate links, Please provide them. We can use those links to purchase that help your channel too. Thanks Mate

  • @soumavanag5025
    @soumavanag5025 3 ปีที่แล้ว

    Thanks :)

  • @SuperYouthful
    @SuperYouthful 4 ปีที่แล้ว

    Int Roman = input();
    Int divide = 0;
    Int thousand;
    Int fiveHundred;
    Int oneHundred;
    Int fifty;
    Int ten;
    Int five;
    Int one;
    Thousand = Roman / 1000;
    Divide = Roman - 1000* Thousand;
    FiveHundred = Divide /500;
    Divide = Divide - 500 * FiveHundred;
    OneHundred = Divide /100;
    Divide = Divide - 100* Onehundred;
    Continue for 50 and 10 and 5 and 1...
    If (onethousand > 0){
    For (i=onethousand, i--, i>0)
    System.out.print("M");
    Continue for the REST OF the Num.

  • @analogylibrary
    @analogylibrary 4 ปีที่แล้ว

    Greatly explained!!

  • @MadhusudanBhosale
    @MadhusudanBhosale 4 ปีที่แล้ว +1

    Amazing logic, Sir!

  • @saddamahmad2310
    @saddamahmad2310 4 ปีที่แล้ว

    thank you very much sir for this video

  • @keshavendraps
    @keshavendraps 4 ปีที่แล้ว +2

    950 should be CML or LM?

  • @vihangafernando6644
    @vihangafernando6644 ปีที่แล้ว

    Hi sir i'm an intern SE and I have been following your content for sometimes. It took me more than 6hrs to complete this question. How can I improve my skills on these type of questions.I'll attach my code in another comment . Thank you for you content. Guidance from the community would be also nice :).

    • @vihangafernando6644
      @vihangafernando6644 ปีที่แล้ว

      public class Calculator {
      public static void main(String[] args) {
      String s = integerToRoman(1994);
      System.out.println(s);
      }
      private static String integerToRoman(int input) {
      int[] intArr = {1,4, 5, 9,10,40, 50,90, 100,400, 500, 900,1000};
      int module = 0;
      int value = input;
      StringBuilder stringBuilder = new StringBuilder("");
      for (int index = intArr.length - 1; index >= 0; index--) {
      module = value / intArr[index];
      stringBuilder.append(stringGenerator(index,module));
      value = value- module* intArr[index];

      }
      return stringBuilder.toString();
      }
      private static String stringGenerator(int index, int module) {
      String[] romanArr = {"I","IV", "V","IX", "X", "XL","L","XC", "C","CD" ,"D","CM", "M"};
      String s = "";
      for (int i = 0; i < module; i++) {
      s = s + romanArr[index];
      }
      return s;
      }
      }

  • @wdwuccnxcnh7022
    @wdwuccnxcnh7022 3 ปีที่แล้ว

    Thanks man!

  • @mayoorm909
    @mayoorm909 4 ปีที่แล้ว +1

    👌

  • @kartikmahendrajalal5660
    @kartikmahendrajalal5660 4 ปีที่แล้ว

    Thanks, bro

  • @user-dv5ps3qd4g
    @user-dv5ps3qd4g 2 ปีที่แล้ว

    I love your chanel, Thank you very much for the content.
    About this question, the answer you gave is not correct, for example 499 in roman is "ID" but your code returns "CDXCIX".

    • @adolfocarrillo248
      @adolfocarrillo248 2 ปีที่แล้ว

      NoUuuuuuuu, your´re wrong, He´s right🤥

  • @joetorres4933
    @joetorres4933 3 ปีที่แล้ว

    The first array value of units has a “ not a ".

  • @TheDheerendraJaiswal
    @TheDheerendraJaiswal 4 ปีที่แล้ว

    Hello sir, waiting for your oauth2 tutorials..

  • @ameyamahadevgonal8130
    @ameyamahadevgonal8130 3 ปีที่แล้ว

    At the start of the problem it looked like a mount everest but after the explanation it looked look nothing

  • @Mohit-il9gx
    @Mohit-il9gx 3 ปีที่แล้ว

    6:10 i did 🤣

  • @by-Org
    @by-Org 2 ปีที่แล้ว

    why didn't you end

  • @snehanair2246
    @snehanair2246 3 ปีที่แล้ว

    can u also mention the time and space complexity please?

    • @soumavanag5025
      @soumavanag5025 3 ปีที่แล้ว +1

      t(n) = o(number of digits in n)

  • @meenakshibhatia2537
    @meenakshibhatia2537 4 ปีที่แล้ว

    How do you get the index as the actual digit? Index would be 0,1,2,3 and so on.

    • @dangels666
      @dangels666 3 ปีที่แล้ว

      Because for 0th index he is storing empty value. hence for each index correct value is picked up. if you don't store empty index at first, then you would have to fetch by array[index -1]

  • @NitinSingh-yc7rg
    @NitinSingh-yc7rg 3 ปีที่แล้ว

    lol this question😂😂😂

  • @emanresplandor3878
    @emanresplandor3878 4 ปีที่แล้ว

    wow we have somewhat the same solution wtf..

  • @ZhouHaibo
    @ZhouHaibo 3 ปีที่แล้ว

    Wow, but this solution is slow, just beat 20% of other solutions in Java. Maybe too many calculations in return result that slow.

  • @ZhouHaibo
    @ZhouHaibo 3 ปีที่แล้ว

    That is O(1) time and O(1) space, you are cheating, men:)

  • @victorseba6410
    @victorseba6410 3 ปีที่แล้ว

    U kinda talk a lot

  • @FredOooUnavailable
    @FredOooUnavailable 3 ปีที่แล้ว

    Why don't you use an array of array where the first level is indexed by p = [0, 1, 2, 3] that you can use as [10**0, 10**1, 10**2, 10**3] = [1, 10, 100, 1000] ?
    So if you loop on p--, you can get every thing with romans[ p ][ num / 10**p ]