HackerRank - Super Reduced Strings | Full solution with visuals and examples | Study Algorithms

Поділитися
Вставка
  • Опубліковано 16 гру 2024

КОМЕНТАРІ • 30

  • @starScreamScreaming
    @starScreamScreaming 3 роки тому

    this guy speaks with confidence

  • @marycampbell5264
    @marycampbell5264 9 місяців тому

    Eloquent solutions as usual.

  • @lohithaadapala6989
    @lohithaadapala6989 Рік тому

    The best solution I've seen. Thanks man : )

  • @thedevguild7525
    @thedevguild7525 2 роки тому +1

    Wow! I like your explanations! It certainly helps a lot!

  • @helsinkired8523
    @helsinkired8523 3 роки тому +1

    Great video sir. Looking for more.

  • @stanislavmozolevskiy8346
    @stanislavmozolevskiy8346 2 роки тому +2

    Good explanation, really simple solutions as well and supper easy to understand. Once you said Stack I pretty much came up with the same solution. :) thank you Nikhil !

    • @nikoo28
      @nikoo28  2 роки тому

      So happy I could help you out.

    • @fathimasyed4232
      @fathimasyed4232 11 місяців тому

      same here i was doing iteration first.

  • @tejasbavkar2811
    @tejasbavkar2811 2 роки тому +1

    Thank you sir...💗

  • @senthilkumar3000
    @senthilkumar3000 2 роки тому

    Good explanation

  • @mithraravi9628
    @mithraravi9628 3 роки тому

    Can we use xor operations between characters of the string and get result for this?

  • @lovely_612
    @lovely_612 3 роки тому

    Thank you ❤

  • @beka3304
    @beka3304 Рік тому

    public static String superReducedString(String s) {
    Map charCount = new HashMap();
    for (char c : s.toCharArray()) {
    charCount.put(c, charCount.getOrDefault(c, 0) + 1);
    }
    Set set = new TreeSet();
    for (char c : s.toCharArray()) {
    if (charCount.get(c) % 2 == 1) {
    set.add(c);
    }
    }
    return (!set.isEmpty()) ? set.toString() : "Empty String";
    }

  • @thedevguild7525
    @thedevguild7525 2 роки тому

    Hi Sir, it would be great if you have JS version of the code.

    • @nikoo28
      @nikoo28  2 роки тому +2

      I can’t provide the solution in JS but you can check the complete code in the video description…if you understand the logic correctly..writing in JS shouldn’t be a problem.

  • @OmKumar-lp1em
    @OmKumar-lp1em 11 місяців тому

    def short(s):
    #s=aaabccddd
    a=list(s)
    b=set(s)
    for i in b:
    c=s.count(i)
    if c%2==1:
    for j in range(c-1):
    a.remove(i)
    else:
    for j in range(c):
    a.remove(i)
    d=''.join(a)
    if len(d)==0:
    return "empty string"
    else:
    return d
    s="aabbb"
    print(short(s))
    I wrote this but 6 test cases failed

    • @nikoo28
      @nikoo28  11 місяців тому

      have you tried debugging?

  • @nancym8049
    @nancym8049 2 роки тому

    Sir Code for final thought

    • @nikoo28
      @nikoo28  2 роки тому +1

      What code did you come up with? I can help you understand your error.
      If I give you the solution right away, you wouldn’t learn. That is just the teacher in me speaking 🙂

    • @nancym8049
      @nancym8049 2 роки тому

      @@nikoo28 Great Teacher😄

  • @shubhammaske3504
    @shubhammaske3504 2 роки тому

    But this Approach will not work with this type of string ---> "abbxayzz" !

    • @nikoo28
      @nikoo28  2 роки тому

      what output are you expecting for this particular string?

    • @nikoo28
      @nikoo28  2 роки тому +1

      for the string "abbxayzz" the output will be -> "axay"...and the code works as expected.
      Please clarify the doubt you are facing.

    • @shubhammaske3504
      @shubhammaske3504 2 роки тому +1

      @@nikoo28 Output should be "xy" only.

    • @nikoo28
      @nikoo28  2 роки тому +1

      abbxayzz
      -> (remove b) axayzz
      -> (remove z) axay
      That’s it…you cannot remove ‘a’ because they are not consecutive

    • @shubhammaske3504
      @shubhammaske3504 2 роки тому

      @@nikoo28 got it, thank you