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

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

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

  • @shashwat_tiwari_st
    @shashwat_tiwari_st  3 หลายเดือนก่อน +4

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

  • @yourmirror6
    @yourmirror6 3 หลายเดือนก่อน

    Very well optimised really amazing problem solving 🎉

  • @eklavya22k34
    @eklavya22k34 3 หลายเดือนก่อน

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

  • @nakulsonkusare
    @nakulsonkusare 3 หลายเดือนก่อน +3

    Love it❤

  • @engineer9503
    @engineer9503 3 หลายเดือนก่อน +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  3 หลายเดือนก่อน

      @@engineer9503 XP

    • @engineer9503
      @engineer9503 3 หลายเดือนก่อน

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

    • @engineer9503
      @engineer9503 3 หลายเดือนก่อน

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

  • @unboxingadda8161
    @unboxingadda8161 3 หลายเดือนก่อน

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

  • @RohitKumar-dz8dh
    @RohitKumar-dz8dh 3 หลายเดือนก่อน +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  3 หลายเดือนก่อน +1

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

    • @RohitKumar-dz8dh
      @RohitKumar-dz8dh 3 หลายเดือนก่อน

      @@shashwat_tiwari_st Thanks 😊

  • @tejas2636
    @tejas2636 3 หลายเดือนก่อน

    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 3 หลายเดือนก่อน

      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 3 หลายเดือนก่อน

      ask chatgpt

    • @shashwat_tiwari_st
      @shashwat_tiwari_st  3 หลายเดือนก่อน +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 3 หลายเดือนก่อน

      ​@@shashwat_tiwari_st ok Thank you sir 🙌🏻

  • @PiyushSharma-we8yd
    @PiyushSharma-we8yd 3 หลายเดือนก่อน +1

    You are saviour😍

  • @GirjeshSharma-zv3xo
    @GirjeshSharma-zv3xo 3 หลายเดือนก่อน +2

    love from france♥

  • @priyanshkumar17
    @priyanshkumar17 3 หลายเดือนก่อน +1

    Done !!!✅✅✅✅