1717. Maximum Score From Removing Substrings | Leetcode Daily Challenge | DSA | Hindi

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

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

  • @rutujasurve4172
    @rutujasurve4172 Месяц назад

    Very well optimised really amazing problem solving 🎉

  • @eklavya22k34
    @eklavya22k34 Месяц назад

    Thanks, it looked so tough, u made it doable and easy to understand.
    Gd work. Gd deeds.

  • @shashwat_tiwari_st
    @shashwat_tiwari_st  Месяц назад +4

    Added Timestamps! Like target for this video is 90. Please do like, if you understood the solution.😄

  • @unboxingadda8161
    @unboxingadda8161 Месяц назад

    osm sir but one request from my side pls try to make video till 12pm

  • @nakulsonkusare
    @nakulsonkusare Месяц назад +3

    Love it❤

  • @RohitKumar-dz8dh
    @RohitKumar-dz8dh Месяц назад +2

    Thanks 😊, sir to hum data to overwrite karne k baad reverse kese kar karte hai jisse previous data mil jayega, jese shop Wale data recover kar lete hai us trah hum programing me manually kese kare .

    • @shashwat_tiwari_st
      @shashwat_tiwari_st  Месяц назад +1

      @@RohitKumar-dz8dh data overwrite hogya toh nhi milta.
      Jbtk overwrite nhi hota tbtk hi retrieve ho sakta hai.

    • @RohitKumar-dz8dh
      @RohitKumar-dz8dh Месяц назад

      @@shashwat_tiwari_st Thanks 😊

  • @engineer9503
    @engineer9503 Месяц назад +3

    sir please tell me which pen tablet are you using because aapki writing kaafi achi aati h please tell me

    • @shashwat_tiwari_st
      @shashwat_tiwari_st  Месяц назад

      @@engineer9503 XP

    • @engineer9503
      @engineer9503 Месяц назад

      @@shashwat_tiwari_st sir ye pta tha xp h but there are many models of xp pen tablet please model bta dijiye

    • @engineer9503
      @engineer9503 Месяц назад

      @@shashwat_tiwari_st deco mini 7 or star g460 ........

  • @tejas2636
    @tejas2636 Месяц назад

    Sir, My approach to solve the question is like : When we are inserting elements in stack we are checking for substring "ab" or "ba" which is giving maximum points. Similiarly we will pop elements from stack one by one and check for the another substring giving minimum points which doesnt require to reconstruct the string again and solve it in 2 pass one for insertion in stack and another for removal. I have written the code for same please check which edge case i am missing.. Please let me know if i am thinking in correct direction or not

    • @tejas2636
      @tejas2636 Месяц назад

      class Solution
      {
      public int maximumGain(String s, int x, int y)
      {
      String toSearch = (x >= y) ? "ab" : "ba";
      Stack stack = new Stack();
      int Points = 0;
      for(char c : s.toCharArray())
      {
      if(stack.isEmpty()) stack.push(c);
      else if(stack.peek() == toSearch.charAt(0) && c == toSearch.charAt(1))
      {
      Points += (x >= y) ? x : y;
      stack.pop();
      continue;
      }

      stack.push(c);
      }
      while(stack.size() > 1)
      {
      char c = stack.pop();
      if(c == toSearch.charAt(0) && stack.peek() == toSearch.charAt(1))
      {
      Points += (x >= y) ? y : x;
      stack.pop();
      }
      }
      return Points;
      }
      }

    • @OnstreamGaming
      @OnstreamGaming Месяц назад

      ask chatgpt

    • @shashwat_tiwari_st
      @shashwat_tiwari_st  Месяц назад +1

      @@tejas2636 hi tejas, ye work nhi krega, first pass ke baad, stack me string reverse order me hoga na, use tmne correct nhi kra...
      try this...
      class Solution
      {
      public int maximumGain(String s, int x, int y)
      {
      String primaryPair = (x >= y) ? "ab" : "ba";
      String secondaryPair = (x >= y) ? "ba" : "ab";
      Stack stack = new Stack();
      int points = 0;
      // Primary pair removal
      for(char c : s.toCharArray())
      {
      if(stack.isEmpty()) {
      stack.push(c);
      }
      else if(stack.peek() == primaryPair.charAt(0) && c == primaryPair.charAt(1))
      {
      points += (x >= y) ? x : y;
      stack.pop();
      }
      else {
      stack.push(c);
      }
      }
      // Collect remaining characters in string after primary pair removal
      StringBuilder remainingString = new StringBuilder();
      while(!stack.isEmpty()) {
      remainingString.insert(0, stack.pop());
      }
      // Secondary pair removal using the same logic
      for(char c : remainingString.toString().toCharArray())
      {
      if(stack.isEmpty()) {
      stack.push(c);
      }
      else if(stack.peek() == secondaryPair.charAt(0) && c == secondaryPair.charAt(1))
      {
      points += (x >= y) ? y : x;
      stack.pop();
      }
      else {
      stack.push(c);
      }
      }
      return points;
      }
      }

    • @tejas2636
      @tejas2636 Месяц назад

      ​@@shashwat_tiwari_st ok Thank you sir 🙌🏻

  • @GirjeshSharma-zv3xo
    @GirjeshSharma-zv3xo Месяц назад +2

    love from france♥

  • @PiyushSharma-we8yd
    @PiyushSharma-we8yd Месяц назад +1

    You are saviour😍

  • @priyanshkumar_iitd
    @priyanshkumar_iitd Месяц назад +1

    Done !!!✅✅✅✅