Solving Meta's 2022 Most Asked Interview Question

Поделиться
HTML-код
  • Опубликовано: 16 ноя 2024

Комментарии • 33

  • @hnkien
    @hnkien 2 года назад +26

    At 4:22, I think we need to pop from stack item 4, not item 2. Great video as usual!

    • @AlgosWithMichael
      @AlgosWithMichael  2 года назад +3

      Woops, yea good catch

    • @goahnary
      @goahnary Год назад +3

      Right. That would be a queue. This works but I think a proper stack makes the most sense when you get to the final result as it removes unmatched pairs.

    • @observer698
      @observer698 25 дней назад +1

      thank you for your comment, I was confused and same to read comments if anyone else got confused :D

  • @correabuscar
    @correabuscar 2 года назад +3

    great explanation, loved it

  • @DominikLoeffler1
    @DominikLoeffler1 5 месяцев назад

    Great explanation! It should be emphasized that "set" here really means a hash table data structure (line 4 in the code). One might be tempted to use a set that's ordered, e.g. std::set in C++ which implements a binary search tree, rebalancing itself with each insert/erase/find. While the latter could be used and would still achieve correctness, it would do so at O(log(N)) vs. the former which does it at O(1). In other words, overall complexity with an ordered set would be much worse at O(N log(N)), after the usual dropping of constants

  • @clot4764
    @clot4764 2 года назад

    I haven’t seen yet but you are the best, just come from your triangle problem, love your videos ❤ please upload more❤

  • @MrMakemusicmike
    @MrMakemusicmike 8 месяцев назад

    Very good.
    Clear information.

  • @Gangrelguy
    @Gangrelguy 5 месяцев назад

    Add two closing parentheses on the end of the string being parsed and it breaks this algorithm.

  • @T-Radi
    @T-Radi 4 месяца назад

    What about "Foo(bar))(". That's valid since the number of ( matches the number of )

  • @destiny-fox1990
    @destiny-fox1990 Год назад +2

    Theres a space o(1) solution thats expected

  • @SmokingNoir
    @SmokingNoir 11 месяцев назад +3

    not how a stack works

  • @furquan5974
    @furquan5974 Год назад

    Excellent explanation 👍

  • @hosseinbafekr6205
    @hosseinbafekr6205 2 года назад

    Thanks for your clear explanation!

  • @JackAbou2
    @JackAbou2 2 года назад

    what platform did you use to code and run the solution? thanks great video BTW

  • @correabuscar
    @correabuscar 2 года назад +4

    you say stack but I see (FIFO) queue at 4:20

    • @user-hd4sl
      @user-hd4sl Год назад

      It was a mistake he made

  • @EMdragonKnight
    @EMdragonKnight 11 месяцев назад

    Good explanation. Is converting the string to an array necessary? Strings in C#/Java also have indeces.

  • @zaza.javakhishvili
    @zaza.javakhishvili 8 месяцев назад

    I do not think that it will work on all string variations.

  • @mikedelta658
    @mikedelta658 9 месяцев назад

    thank you

  • @sameer9368
    @sameer9368 2 года назад +1

    Hi muinos....I am from India....please make more video.... 😎

  • @ravividap1227
    @ravividap1227 2 года назад +1

    Why set and why not simple array?

    • @nitishjoshi2637
      @nitishjoshi2637 2 года назад +1

      In case of an array, you will have to iterate over it to find if it contains the index, which becomes an O(N) operation. In case of a Set, you don't need to iterate and the operation is O(1).

    • @ravividap1227
      @ravividap1227 2 года назад +1

      @@nitishjoshi2637 i did it with arrays 😀 declared an array of size input string length then store unique value at indexes to identify. I could still do it in order of N overall time complexity

    • @nitishjoshi2637
      @nitishjoshi2637 2 года назад

      @@ravividap1227 Yes, the overall time complexity will not change, as the worst case would still be O(N). But if you are looking to optimize your code during interviews or otherwise, using a HashSet would definitely help 🙂

  • @SC2Edu
    @SC2Edu 9 месяцев назад

    Easy but fun

  • @rugvedwagh9434
    @rugvedwagh9434 2 года назад

    First here mike

  • @vinayyelleti2714
    @vinayyelleti2714 2 года назад +1

    stack.pop is char and how this is being added to set of integers..at line 16
    indexToRemove.add(stack.pop());