1717. Maximum Score From Removing Substrings - Day 12/31 Leetcode July Challenge

Поділитися
Вставка
  • Опубліковано 2 сер 2024
  • Larry solves and analyzes this Leetcode problem as both an interviewer and an interviewee. This is a live recording of a real engineer solving a problem live - no cuts or edits!
    Problem: leetcode.com/problems/maximum...
    Twitch: / larryny
    Discord: / discord
    Instagram: / larrysomewhere
    #leetcode #coding #programming
  • Наука та технологія

КОМЕНТАРІ • 10

  • @Algorithmist
    @Algorithmist  22 дні тому +1

    Did you get all the scores?

    • @redfinance3403
      @redfinance3403 22 дні тому

      No, I'm very bad with these stack problems.

  • @tuandino6990
    @tuandino6990 22 дні тому +2

    If the interviewer ask me why I use greedy for this problem, I think i cant explain

  • @user-vq8zo4bi3b
    @user-vq8zo4bi3b 21 день тому

    When choosing between 'ab' or 'ba', there will always be a shared 'a' or 'b' between the two options. An interesting thing happens in this process. For example, '...aba...' will always become '...a...' after removing, regardless of whether you choose to remove 'ab' or 'ba'. Similarly, '...bab...' will always become '...b...'. This behavior extends to longer chunks of 'ab' or 'ba'. Therefore, you should choose to remove 'ab' or 'ba' based on the points x and y.

    • @Algorithmist
      @Algorithmist  21 день тому +1

      that is the invariant that I couldn't figure out, thanks!

  • @rohitkumarpilania94
    @rohitkumarpilania94 21 день тому

    So what id did was:
    1) Remove the string that provides more i.e ab if x > y or vice versa
    2) when you are done with this, you'll have a stack with potential points left in it
    Now see:
    if x > y:
    you'll never find "ab" in stack leftover cause I deleted all of them
    .:. possible stacks are: [aaaaa], [bbbaaa], [bbbbbbbba]
    ans += y*min(a,b)
    if y > x:
    you'll never find "ba" in stack leftover cause I deleted all of them
    .:. possible stacks are: [aaaaaaaa], [aabbbb], [aaaaaab]
    ans += x*min(a,b)

  • @nox3042
    @nox3042 21 день тому

    Still dont understand why hint 1 from the subject is Always True.
    But supposing this statement true, it can be solved like this
    `return max(f(s, x, y, 'a', 'b'), f(s, y, x, 'b', 'a')); ` without inversing all the a's and b's

  • @Hope-ck6hy
    @Hope-ck6hy 15 днів тому

    Do you think i can use count() and replace() to replace the for loop you used?

    • @Algorithmist
      @Algorithmist  15 днів тому

      Maybe? the thing is that you might have aabb which requires the stack

  • @codenocode
    @codenocode 22 дні тому

    yes this was a very specific problem. It's a experiment and make it work type of problem.