Ep5 - Using recursion, check whether a string is a palindrome or not | DSA series
Вставка
- Опубліковано 24 сер 2024
- To check whether a string is palindrome or not is very easy. You can do this question with the help of the FOR loop, but in this video, we will learn how to do this with the help of recursion. Now you might ask, why are we doing this when we already know one method? These basic questions will help you build up your strong base for the harder problems. So don't skip these videos and share them with your friends too.
Practice - bit.ly/39UrBjK
Code available in Cpp, Java, Python - github.com/Lea...
Main channel link - bit.ly/3GBAV7f
DSA Placement series - • DSA Placement series
Recursion playlist - • Recursion
🔴Watch the complete Linked List Series • Linked List Series
To get all updates follow on Instagram
/ frazmohammad
👨💻Utilize free courses, DSA sheet, and articles on Lead Coding website at
Join our telegram channel for all the important announcements
t.me/leadcoding
✨ Hashtags ✨
#DSA #Recursion #Placement #Fraz
Day 5 Done ✅
Congratulations Guys, if you are consistent from last 5 days because 5th & 10th day are the most difficult day of consistency ⚡ By the time you'll reach 21st day you will be champ. 👑 Hope this motivates you all❤😊
Absolutely correct 💯
Points -
1. Basic solution is to use two pointers from middle, from ends OR reverse the string.
2. In recursion, we will only take the loop and convert it to recursion. i.e. we still will have left and right end chars in same call (and not have some mechanism to store and compare in appropriate number of call). L and R represent the substring which needs to be checked for substring. [hence the 0 and n-1 initial values as we need to check whole string at first.]
3. Since, we return boolean as final answer, we will return true/false in base and invalid cases (here base case is a valid case). For Induction step(where we make next call), we don't need to take and/or since this is a Unary recursion tree.
*Note - Recursive solution is "inferior" to iterative solution in terms of space complexity (expected due to stack)
Sorry for the late Fraz bhaiya. But EP 5 is DONE. Thank you for your consistency and I always appreciate you for your 0 to pro
type content.
I have solving palindrome problems using loop, today i learnt new thing that we can solve it using recursions as well. thanks bro.
One small suggestion Fraz bhai ..!! The logic explanation is superb.! In one go I am able to understand. It would be good if you can explain the code also so that it will be easy for us to understand and this helps us to explain to interviewer also in much smoother way. Because these days interviewers are preferring the explanation of code which we write. I know it might look silly suggestion but it helps us a lot.
Can you share 1 problem as a homework like after discussing 1 problem in video, you can give us that topic related problem for solving.
I understood the recursion concept well thanks to you.
+1
I always do the problem using iterative solution 😂 learnt the recursion approach from this video. Thank you so much for hard work and regularity. Keep on doing that, enjoying so much big bro ❤️❤️
Woow I see your comment daily ❤️.
Thanks for writing ☺️
@@LearnYardYT Yeah i love these videos so much because I badly waiting for such bootcamp which covers everything and not wasting time much. I know how you work hard for us. So it is a greatfulness towards you. ❤️
@@LearnYardYT l==r right for base condition why L>=r
@@LearnYardYT can you pls tell me why L>=R in the base condition L== R what is the difference in that
@@ramakrishna4092 it helps when size of string is even , do dry run of {1 2 1 1 2 1},you will understand
You are hard working for us until finish this series I will never give up
I will watch your daily lectures and be consistent
take a bow for ur consistency
Provide assignments for practice daily. This will help everyone.
A small request Fraz to cover more in one video and also plz dry run the code for a few cases. Gives loads of insight like in last video you did ♥️♥️!!! #missionamazon
Yeah, now catch your speed.. Feeling confident. 👍
The way of explaination is mindblowing. Keep it up.
Palindrome problem is now bit easier 🔥🔥
Ep5 also done successfully ✅
Abhi tk sbkuchh mst samajh aa ra 😌
Awesome 🔥
bhai bht acha kaam kra h ....lots of love :)
I think we should increase pace of this course its just a suggestion and you know better than me fraz bhaiya
thank you
With this course, you are giving us more than DSA lessons
You are teaching us discipline perseverance and to show up every day no matter what(which will stay for life)
Thank you so much bhaiya♥
Bhaiya lectures are really good. Like as a beginner I am understanding this recursion series very well but pls suggest how to gain confidence over topic of time and space complexity
JAVA CODE
public class Solution {
public static void main(String []args){
Solution ans= new Solution();
String obj="level";
ans.isPalindrome(obj);
}
public static Boolean Palindrome(int i, int j,String s) {
if(i>=j) return true;
if(s.charAt(i)!=s.charAt(j)) return false;
return Palindrome(i+1,j-1,s);
}
public static Boolean isPalindrome(String s) {
System.out.println(Palindrome(0,s.length()-1,s));
return Palindrome(0,s.length()-1,s);
}
}
iss it necessary tom take the helper functions
Waiting for next topics!
the simplest explanation ever.. loved it.
Concept cleared !!!amazing
Done understood day 5✅
watched till end 👍
Thnq bhaiya for ur every effort
superb video
having no doubt😊
Eagerly waiting for the video daily same as i used to wait for a show on TV in my childhood😄😁
Thankyou bhaiya for this session
Thanks for the video
Day 5
Consistency✌✌✌
very good series
#DAY_5
Consistency OP🔥🔥🔥🔥
video best like previous.n/2 is write because there is 0 to 4 and all i assumen .baki no doubts.ur videos is like 6 baj gaya aaaj ka video chalo kar lete hai .im student .but ik working professional ke liye ye daily challange time ki waje se kaffi accha lag raha hoga superb bhaiya.consistent op
Very clear
you are one of the best teacher keep uploading videos brother...
Thanks a ton
Fraz bhai 🔥🔥
Great video !
So ideally , out depends on inner output is varied in this recurssion
wonderful video
so great brother
this is very expensive seriese
🥰🥰🥰
very helpful
Very well explained ! ..Thanks for your support
Thanks bhaiya
Day 5 completed
Please give more questions for practice and homework
Present ! I'm owner to you for this lovely video ! Please make more video on recursion ! It Will help me more to strong my DSA Knowledge !🙌✔
oosm explanation
Thanks
Thanks!
bhaiya, can you please share the syllabys plan for your course? means expected dates for completion of topics.
thank you sir
Good Video
Nice explanation bhaiya.
Thank you for this video
solved this problem using recursion for the first time...
Class 5 done☑
Ep: 5 Done !
waiting for more such content!!!
THANKS
Nicely explained!
Great
It is very good
Lec 5 Done
thanks
Episode 5 done ✅
done bhaiya..completed
day 5 done
Complete Day 5 ❤️
nice explanation keep up the good work.
Bhaiya we want more questions🔥🔥 great explaination
Sorry for the late bhaiya 🥲
But covering all your videos
Keep making , its very effective ❤️
I like yours video's 🥰
😊😊😊Thank u bhaiya
Now revision 💪
class PalindromClass{
public static void main(String args[]) {
String input = "racecar";
boolean result = PalindromClass.Palindrom(0, input.length()-1, input);
System.out.println(result);
}
public static boolean Palindrom(int l, int r, String s) {
if(l>=r) return true;
if(s.charAt(l) != s.charAt(r)) return false;
return Palindrom(l+1, r-1, s);
}
}
Thank you for so good digestible content. One request can you come up with a small scenario of real time project where we are using these DSA concepts. As of filling a form where next questions are based on previous one and have a concept of DSA. Thank you in advance...
Forgot to comment, now done😁
Thanks 😁
nice video
Lecture 5 - ☑
#Dsabyfaraz
#recursion❤
Good
Done✅
great lecture😊
Video is good with the analysis.
hw done bhaiya
there is another approach that i used for solving this question hope it can help someone
bool pallindrom(int index,int size, string &s)
{
if(index>=size/2)
return true;
if(s[index]!=s[size-index-1])
return false;
pallindrom(index+1,size,s);
}
bool isPalindrome(string &s)
{
return pallindrom(0,s.size(),s);
}
Day 5 Done🙂
We can do it this way as well without making two diff functions.
bool isPalindrome(std::string str, int s = -1, int e = -1){
if(s==-1 && e==-1){
s = 0; e = str.size() - 1;
}else if (s > e){
return true;
}
if(str[s] == str[e]) return isPalindrome(str, ++s, --e);
return false;
}
int main(){
// TODO: Testcase
// Start Each Test Case from here.
std::string s; std::cin >> s;
std::cout
Day 5
Done✅✅
Sir, please cover data structures like vectors, maps stacks, queues etc in details.
Please sir it will be very helpful for people like me who are absolute beginner .
Please all these data structures just after this recursion sessions !!
enjoying
Ep5 DONE.
#day 5 -done
Very useful video because since 5 days I solve this question but this solution is best .
Bhaiya can you make a video for iteratively Approach please.
completed👍
Please take more examples or questions on logarithmic time complexity. N also tell please bhaiyaa how to find or think when we can say this is taking log time/space
Edit the video to zoom on the code you are writing , it will be more comfortable and good for viewing
I was check this channel at 6pm but kuch nahi tha🤕 when you upload this lecture☹️
Day 5 completed
8th june - done (Started Late)
Thank you soo much bhiya for your efforts 🙌 present
Thanks for writing ❤️
Sir give some other practice problems for hw