Well said sir, In one go I have solved this problem keep going with this brief explanation sir..
@techdose4u10 күн бұрын
Great 👍
@vikasvoruganti749011 күн бұрын
class Solution { public: bool canMakeSubsequence(string str1, string str2) { int n1=str1.size(); int n2=str2.size(); int j=0; for(int i=0;i
@mayukhbhowmik93410 күн бұрын
I feel your this solution in little bit of overwhelming....I tried Simply over two pointer approach:class Solution { private: bool Check(char x, char y) { // Check if x matches y directly or can transform into y by incrementing return (x == y || (x + 1 - 'a') % 26 + 'a' == y); } public: bool canMakeSubsequence(string str1, string str2) { int first = 0, second = 0; // Edge Case: If str1 is shorter than str2, it's impossible if (str1.length() < str2.length()) return false; // Two-pointer technique while (first < str1.length() && second < str2.length()) { if (Check(str1[first], str2[second])) { first++; second++; } else { first++; } } // If we traversed all of str2, it's possible to form it return second == str2.length(); } };