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 .
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
Very well optimised really amazing problem solving 🎉
Thanks, it looked so tough, u made it doable and easy to understand.
Gd work. Gd deeds.
Added Timestamps! Like target for this video is 90. Please do like, if you understood the solution.😄
osm sir but one request from my side pls try to make video till 12pm
Love it❤
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 .
@@RohitKumar-dz8dh data overwrite hogya toh nhi milta.
Jbtk overwrite nhi hota tbtk hi retrieve ho sakta hai.
@@shashwat_tiwari_st Thanks 😊
sir please tell me which pen tablet are you using because aapki writing kaafi achi aati h please tell me
@@engineer9503 XP
@@shashwat_tiwari_st sir ye pta tha xp h but there are many models of xp pen tablet please model bta dijiye
@@shashwat_tiwari_st deco mini 7 or star g460 ........
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
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;
}
}
ask chatgpt
@@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;
}
}
@@shashwat_tiwari_st ok Thank you sir 🙌🏻
love from france♥
You are saviour😍
Done !!!✅✅✅✅