Reverse Vowels of a String

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 พ.ย. 2024

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

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

    3:06
    Since java 9, we can create an immutable collection using the following
    Set vowels = Set.of('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U');

  • @HolisticDeveloper
    @HolisticDeveloper 5 ปีที่แล้ว +7

    You have a natural way of explaining things. Nicely done!

  • @Cr4zyVib3
    @Cr4zyVib3 5 ปีที่แล้ว +20

    I NEVER comment, but you deserve more subscribers. Thank you!

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

      you all prolly dont give a shit but does any of you know of a trick to get back into an Instagram account??
      I somehow lost the account password. I appreciate any assistance you can give me!

  • @RawBert
    @RawBert 2 ปีที่แล้ว +1

    You can just create the vowels as lowercase and when checking, check current char in set as lowercase

  • @jreneew2
    @jreneew2 5 ปีที่แล้ว +2

    I did this using 2 for loops. I created an extra array with the size of the string. Then iterated through the array, if it was a vowel, add it to the array at the index it was at. Then go through the string again and grab the last element of the vowel array and added it to the string. I also used string builder to make sure I wasn't creating a new string every time

  • @pkumarshekar
    @pkumarshekar 5 ปีที่แล้ว +3

    Hi Kevin, I am very grateful for the short but extremely well-explained videos. Please do not stop since you are helping a lot of people getting better lives. I have a request. Could you please solve Last Stone Weight II (Problem 981) on Leetcode?

    • @KevinNaughtonJr
      @KevinNaughtonJr  5 ปีที่แล้ว +3

      Thanks Pavan and don't worry I won't the whole purpose of my channel is to help people so I'm super happy to hear it's doing that! I'll make sure to put that problem on my list :)

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

    We don't need to swap the chars when i == j, that's an improvement

  • @algorithmimplementer415
    @algorithmimplementer415 5 ปีที่แล้ว +2

    Please do more videos on backtracking with explanation on time complexity. I think many of us don’t get it right.

  • @ariellyrycs
    @ariellyrycs 5 ปีที่แล้ว

    It’s crazy thinking that if you don’t have any vowels you will be swapping one for the same. That’s so clever, i would’ve done this more complicated.

  • @RyanTorrecampo
    @RyanTorrecampo 5 ปีที่แล้ว

    I love your videos man. Your explanations for every problem are easy to understand. Thanks for always putting out more content!

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

    Thanks Kevin, really helpful..good to see explaining time complexities in the videos.

  • @roystonnoronha4184
    @roystonnoronha4184 5 ปีที่แล้ว +1

    Great explanation

  • @aminvakhshouri2378
    @aminvakhshouri2378 5 ปีที่แล้ว +1

    Kevin, thank you for awesome videos. I've been following your videos for a while. I will have a phone screen interview with Amazon for a DE position next week. I'd like to connect and get some advice from you.

  • @sateeshtata
    @sateeshtata 5 ปีที่แล้ว

    Thanks for posting. Nice explanation!

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

    Thank you !

  • @Pizzasleaze
    @Pizzasleaze 5 ปีที่แล้ว +1

    Could you go over the Game of Life problem? Thanks, I love your videos!

  • @sandarabian
    @sandarabian 5 ปีที่แล้ว

    Why not just use a for loop where i is your starting index, and keep decrementing j until i and j meet while performing the same swapping of vowels? Seems like it would be more readable and prevent you from making mistakes where you'd be stuck in an infinite loop.

  • @AnkitKumar-tp8hc
    @AnkitKumar-tp8hc 5 ปีที่แล้ว +1

    Can anyone explain to me how is the time complexity O(n) in this solution , because we have nested loops?

    • @LP5657
      @LP5657 5 ปีที่แล้ว +1

      Although you have nested loops here, if you think about the condition of the inner loop it doesn't actually go through the string more than a string for length 'n' because it will stop if it reaches the end of the string.

  • @jacobhaff7602
    @jacobhaff7602 5 ปีที่แล้ว

    These videos are really helpful!

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

    Thanks a lot, this was great!

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

    500th LIKE ! Good job brotha !

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

    A much cleaner approach could be using a stack.
    Linear time, linear space complexity
    private String main(String s) {
    String str= "";
    String vowels= "aeiouAEIOU";
    Stack stack = new Stack();
    for(int i=0;i

  • @Monkeydoge
    @Monkeydoge 5 ปีที่แล้ว

    Not sure if you’d know, but do you know what should be expected of a Goldman Sachs on-site interview?
    Also great videos, you’ve got really great explanations

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

    Well, I think interviewer want you to swap this way. But as we definately have to make new string in java I collected all the vowels in stack and the second time popped them without swapping. It's slower but much simpler. I'll try to modify a little you approach to get a better result. Upd. my approach didn't work

  • @sujansarathighosh6455
    @sujansarathighosh6455 5 ปีที่แล้ว

    Hi Kevin,
    Good one !
    One condition what if no vowels in string, we not covering, i guess if we use continue inside the two inner while loop, it will cover no vowels as well.

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

      Only last character will be swapped by itself and loop will terminate. Everything is fine.

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

    Great solution. I would add small correction HashSet vowels = new HashSet(); instead of Set vowels = new HashSet(); (line 3)

  • @faraz7409
    @faraz7409 5 ปีที่แล้ว

    thanks kev!

  • @SilentGuardian1999
    @SilentGuardian1999 5 ปีที่แล้ว

    Why not use regex.pattern for vowels??

  • @-_ShahriarRahman
    @-_ShahriarRahman 5 ปีที่แล้ว

    Can you do tuts on gsoc kevin???

  • @ajr1791ze
    @ajr1791ze 5 ปีที่แล้ว

    how u knw it was ask in amazon

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

    you are loosing weight !!!

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

    Vowels are 'a', 'e', 'i' , 'o' , 'u'.

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

    Why is j=s.length()-1 and not just s.length()

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

      nevermind, I got it

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

    would it work if I used if statements for the test cases instead of the while (inner ones)

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

      give it a try :)

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

      @@KevinNaughtonJr it worked :) but the test cases where more speciefic than I expected them to be. Well I guess it's time I start learning when to implement this approach for optimal solutions.
      PS: thanks for the the videos solution.

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

      Amir LS591 anytime!

  • @chiragchatwani9124
    @chiragchatwani9124 5 ปีที่แล้ว

    Hey You make awesome content but can you make a video dedicated on How to use collection framework and all its method I am new to java and its very confusing please. Thanks in advance

  • @ashiqimran5961
    @ashiqimran5961 5 ปีที่แล้ว

    Hi Kevin, Can you make a video of "leetcode.com/problems/reconstruct-itinerary/"? Thanks in advance.

  • @109_simran3
    @109_simran3 3 ปีที่แล้ว

    TLE

  • @ramkrishnasingh56
    @ramkrishnasingh56 5 ปีที่แล้ว

    Noob questions I just wrote thing same but put i++ and j++ in while loop where you put them in braces and it didn't work I don't know why so.
    Here is the link to my solution pastebin.com/mNQjicbw

  • @Krishna42570
    @Krishna42570 5 ปีที่แล้ว

    Yours rate of posting videoss per day was very less ...i was disgusted..

    • @jak0495
      @jak0495 5 ปีที่แล้ว +1

      he's been slacking i'm disgusted as well.

    • @sakethram1765
      @sakethram1765 5 ปีที่แล้ว +6

      Ummm Disgusted? I think the word you are looking for is "Disappointed".

    • @LazySteezy
      @LazySteezy 5 ปีที่แล้ว

      hahaha