1
00:00:00,140 --> 00:00:01,040
Welcome back.

2
00:00:01,040 --> 00:00:06,770
Let's now get into the code for solving the longest palindromic substring question.

3
00:00:06,770 --> 00:00:13,010
So the code that I have over here is the same thing that we have written for the tabulation approach

4
00:00:13,010 --> 00:00:17,300
for the palindromic substrings question, which is something that we have previously discussed.

5
00:00:17,330 --> 00:00:22,940
Now, as we have discussed in the previous video, we would just need to make a slight tweak over here

6
00:00:22,940 --> 00:00:27,230
to modify that code to be able to solve this particular question.

7
00:00:27,230 --> 00:00:27,650
Okay.

8
00:00:27,650 --> 00:00:31,070
So all that we need to do is over here okay.

9
00:00:31,070 --> 00:00:38,540
For every I j combination we just need to check whether depee at I j is a palindrome.

10
00:00:38,540 --> 00:00:42,650
And if it is a palindrome then we will just have a variable.

11
00:00:42,650 --> 00:00:46,640
Let's say we call it longest and we have to initialize it over here.

12
00:00:46,640 --> 00:00:52,550
So let's say net longest be an empty string okay.

13
00:00:52,550 --> 00:01:00,620
And over here we will say longest is equal to s dot slice I2J plus one okay.

14
00:01:00,620 --> 00:01:06,530
So I to j because we just need to take this substring over here which is represented by depee at I j.

15
00:01:06,530 --> 00:01:08,390
And we need to assign it to longest.

16
00:01:08,390 --> 00:01:10,160
Now why does this work.

17
00:01:10,160 --> 00:01:15,470
The reason for that is because we are iterating through the DP table in a length wise manner.

18
00:01:15,470 --> 00:01:22,130
Whenever we get a new DP at I j to be true, the length of that particular substring would be either

19
00:01:22,130 --> 00:01:29,390
equal to or greater than the previously true dp at I, j right, or substring, and therefore we just

20
00:01:29,390 --> 00:01:30,440
need to keep doing that.

21
00:01:30,440 --> 00:01:36,050
And ultimately whatever value is there in longest would just need to be returned so we can return it

22
00:01:36,050 --> 00:01:36,500
over here.

23
00:01:36,500 --> 00:01:38,210
So return longest.

24
00:01:38,210 --> 00:01:39,080
And that's it.

25
00:01:39,080 --> 00:01:40,490
It should solve this question.

26
00:01:40,490 --> 00:01:44,450
Now let's go ahead and run this code and see if it's passing all the test cases.

27
00:01:45,230 --> 00:01:45,590
All right.

28
00:01:45,590 --> 00:01:46,280
It's working.

29
00:01:46,280 --> 00:01:50,090
You can see it's passing all the test cases do make use of the user logs.

30
00:01:50,090 --> 00:01:53,300
It will help you debug your code in case you're stuck at some point.
