You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: dsa-solutions/lc-solutions/0000-0099/0001-two-sum.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,7 @@ tags:
11
11
- JavaScript
12
12
- TypeScript
13
13
description: "This is a solution to the Two Sum problem on LeetCode."
14
+
sidebar_position: 1
14
15
---
15
16
16
17
In this page, we will solve the Two Sum problem using three different approaches: brute force, hash table, and two-pointer technique. We will provide the implementation of the solution in JavaScript, TypeScript, Python, Java, C++, and more.
Copy file name to clipboardExpand all lines: dsa-solutions/lc-solutions/0000-0099/0002-Add-Two-Numbers.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,7 @@ tags:
9
9
- Add Two Numbers
10
10
- LeetCode
11
11
description: "This is a solution to the Add Two Numbers problem on LeetCode."
12
+
sidebar_position: 2
12
13
---
13
14
14
15
In this page, we will solve the Add Two Numbers problem. We will provide an overview of the problem, the intuition and approach to solve it, the implementation, and the code in various languages, along with a detailed explanation of the solution and its complexity analysis. Let's start by understanding the problem.
Copy file name to clipboardExpand all lines: dsa-solutions/lc-solutions/0000-0099/0003-Longest-Substring-Without-Repeating-Characters.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@ tags:
7
7
- String
8
8
- Sliding Window
9
9
description: "This is a solution to the Longest Substring Without Repeating Characters problem on LeetCode."
10
+
sidebar_position: 3
10
11
---
11
12
12
13
In this page we will solve the problem [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) from LeetCode.
Copy file name to clipboardExpand all lines: dsa-solutions/lc-solutions/0000-0099/0004-Median-of-two-Sorted-Array.md
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,8 @@ tags:
7
7
- Binary Search
8
8
- Divide and Conquer0
9
9
- LeetCode
10
-
description: Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be $O(log (m+n))$.
10
+
description: Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
11
+
sidebar_position: 4
11
12
---
12
13
13
14
In this page, we will solve the problem [Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/description/) from LeetCode. We will provide multiple approaches to solve the problem along with the code implementation and the complexity analysis of the code.
|[Longest Palindromic Substring on LeetCode](https://leetcode.com/problems/longest-palindromic-substring/description/)|[Longest Palindromic Substring Solution on LeetCode](https://leetcode.com/problems/longest-palindromic-substring/editorial/)|[gabaniyash846](https://leetcode.com/u/gabaniyash846/)|
16
-
17
12
## Problem Statement
18
13
19
14
Given a string `s`, return the longest palindromic substring in `s`.
20
15
21
16
### Examples
22
17
23
18
**Example 1:**
19
+
24
20
```plaintext
25
21
Input: s = "babad"
26
22
Output: "bab"
27
23
Explanation: "aba" is also a valid answer.
28
24
```
29
25
30
26
**Example 2:**
27
+
31
28
```plaintext
32
29
Input: s = "cbbd"
33
30
Output: "bb"
34
31
```
35
32
36
33
### Constraints
34
+
37
35
-`1 <= s.length <= 1000`
38
36
-`s` consist of only digits and English letters.
39
37
@@ -42,153 +40,172 @@ Output: "bb"
42
40
### Approach 1: Check All Substrings
43
41
44
42
#### Intuition
43
+
45
44
We can start with a brute-force approach. We will simply check if each substring is a palindrome, and take the longest one that is.
46
45
47
46
#### Algorithm
47
+
48
48
1. Create a helper method `check(i, j)` to determine if a substring is a palindrome.
49
49
2. Use two pointers to iterate from the start and end of the substring towards the center.
50
50
3. If characters at both pointers are equal, move the pointers inward.
51
51
4. Use nested loops to check all possible substrings and use the helper method to determine if they are palindromes.
-**Time complexity**: $O(n)$ - Manacher's algorithm runs in linear time.
189
203
-**Space complexity**: $O(n)$ - We use an array of length `n` to store the lengths of palindromes.
190
204
191
205
### Conclusion
206
+
192
207
We discussed four approaches to solve the "Longest Palindromic Substring" problem, each with varying complexities and trade-offs. The dynamic programming and center expansion approaches provide a good balance of simplicity and efficiency for practical use cases, while Manacher's algorithm offers the optimal theoretical performance.
0 commit comments