title
stringlengths
1
100
titleSlug
stringlengths
3
77
Java
int64
0
1
Python3
int64
1
1
content
stringlengths
28
44.4k
voteCount
int64
0
3.67k
question_content
stringlengths
65
5k
question_hints
stringclasses
970 values
✅3 Method's || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥
two-sum
1
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe Two Sum problem asks us to find two numbers in an array that sum up to a given target value. We need to return the indices of these two numbers.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. One brute force ...
3,674
Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice. You can return the answer in any order. **Example 1:** **Input:** nums...
A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations. So, if we fix one of the numbers, say x, we have to scan ...
Hash Table Concept-->Python3
two-sum
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
263
Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice. You can return the answer in any order. **Example 1:** **Input:** nums...
A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations. So, if we fix one of the numbers, say x, we have to scan ...
Sum MegaPost - Python3 Solution with a detailed explanation
two-sum
0
1
If you\'re a newbie and sometimes have a hard time understanding the logic. Don\'t worry, you\'ll catch up after a month of doing Leetcode on a daily basis. Try to do it, even one example per day. It\'d help. I\'ve compiled a bunch on `sum` problems here, go ahead and check it out. Also, I think focusing on a subject a...
1,045
Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice. You can return the answer in any order. **Example 1:** **Input:** nums...
A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations. So, if we fix one of the numbers, say x, we have to scan ...
[VIDEO] Visualization of O(n) Solution Using a Hash Table
two-sum
0
1
https://www.youtube.com/watch?v=luicuNOBTAI\n\nInstead of checking every single combination of pairs, the key realization is that for each number in the array, there is only **one** number that can be added to it to reach the target.\n\nWe combine this with a hash table, which can look up values in constant time, to ke...
4
Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice. You can return the answer in any order. **Example 1:** **Input:** nums...
A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations. So, if we fix one of the numbers, say x, we have to scan ...
1. (Solution)
two-sum
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIt is a Brute Force Method\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSubtract the target from the list of element from the starting and find the second number. After that search that second number in the list...
2
Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice. You can return the answer in any order. **Example 1:** **Input:** nums...
A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations. So, if we fix one of the numbers, say x, we have to scan ...
Solutions in C++ and Python3 | For Loop
two-sum
0
1
\n# Code\n```C++ []\nclass Solution {\npublic:\n vector<int> twoSum(vector<int>& nums, int target) {\n vector<int>answer;\n for (int i = 0; i < nums.size(); i++){\n for (int j = i + 1; j < nums.size(); j++){\n if (nums.at(i) + nums.at(j) == target){answer.push_back(i); answer....
2
Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice. You can return the answer in any order. **Example 1:** **Input:** nums...
A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations. So, if we fix one of the numbers, say x, we have to scan ...
Binbin's very simple solution! dont understand why so many solutions used user.out........> <
two-sum
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice. You can return the answer in any order. **Example 1:** **Input:** nums...
A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations. So, if we fix one of the numbers, say x, we have to scan ...
✅98.21%🔥HashMap & Time complexity🔥1 line Code 🔥
two-sum
1
1
# Problem\n#### The problem statement describes a classic coding interview question. You are given an array of integers (nums) and an integer (target). Your task is to find two distinct numbers in the array that add up to the target. You need to return the indices of these two numbers.\n\n---\n# Solution\n\n##### 1. Th...
34
Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice. You can return the answer in any order. **Example 1:** **Input:** nums...
A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations. So, if we fix one of the numbers, say x, we have to scan ...
Two sums || 3 easy methods in Python
two-sum
0
1
# Intuition\nMethod 1: A brute-force solution to find two numbers in the nums list that add up to the target value.\n\nMethod 2: By list concept\n\nMethod 3: By Dictionary (more efficient solution)\n# Approach\nMethod 1: \nThe code uses nested loops to iterate over each pair of numbers in the nums list. The outer loop ...
70
Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice. You can return the answer in any order. **Example 1:** **Input:** nums...
A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations. So, if we fix one of the numbers, say x, we have to scan ...
3 Best Solutions explained
two-sum
1
1
https://youtu.be/--qiegimDZM
114
Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice. You can return the answer in any order. **Example 1:** **Input:** nums...
A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations. So, if we fix one of the numbers, say x, we have to scan ...
Easy Python Solution With Explanation 🔥🔥
two-sum
0
1
# Approach\nThis code defines a Python class called `Solution` with a method named `twoSum`. The purpose of this method is to find two numbers in a list (`nums`) that add up to a specific target number (`target`). Here\'s a simple explanation of how it works:\n\n1. Create an empty dictionary called `numsList` to store ...
27
Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice. You can return the answer in any order. **Example 1:** **Input:** nums...
A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations. So, if we fix one of the numbers, say x, we have to scan ...
(VIDEO) Step-by-Step Visualization of O(n) Solution
two-sum
0
1
https://youtu.be/luicuNOBTAI\n\nInstead of checking every single combination of pairs, the key realization is that for each number in the array, there is only **one** number that can be added to it to reach the target.\n\nWe combine this with a hash table, which can look up values in constant time, to keep track of arr...
91
Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice. You can return the answer in any order. **Example 1:** **Input:** nums...
A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations. So, if we fix one of the numbers, say x, we have to scan ...
simple answer with for loop
two-sum
0
1
# Approach\n<!-- Describe your approach to solving the problem. -->\nCreate an empty dictionary called num_dict to store numbers and their indices.\nIterate through the nums array using a for loop, keeping track of the current index and the current number.\nCalculate the complement, which is target - num, where num is ...
2
Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice. You can return the answer in any order. **Example 1:** **Input:** nums...
A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations. So, if we fix one of the numbers, say x, we have to scan ...
Two Sum: faster than hashmap in worst case. uses sort
two-sum
0
1
# Better than Hashmap in worst case\n\nI\'ve seen a lot of solutions that iterate over the list and do hashmap lookup. These solutions often say that they are "worst case $$O(n)$$" time complexity. However, this is false because worst case hashmap lookup is $$O(n)$$, so those solutions are actually worst case $$O(n^2)$...
0
Given an array of integers `nums` and an integer `target`, return _indices of the two numbers such that they add up to `target`_. You may assume that each input would have **_exactly_ one solution**, and you may not use the _same_ element twice. You can return the answer in any order. **Example 1:** **Input:** nums...
A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations. So, if we fix one of the numbers, say x, we have to scan ...
✅Beats 100% || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥
add-two-numbers
1
1
# Intuition:\nThe Intuition is to iterate through two linked lists representing non-negative integers in reverse order, starting from the least significant digit. It performs digit-wise addition along with a carry value and constructs a new linked list to represent the sum. The process continues until both input lists ...
921
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 ...
null
[VIDEO] Step-by-Step Visualization and Explanation
add-two-numbers
0
1
ERROR: type should be string, got "https://www.youtube.com/watch?v=Fs5xgNNoP5c\\n\\nFirst we create a new ListNode, `head`, which will hold our answer. We then traverse the two lists, and at every node, we add the values together, create a new node with the sum, and link it to `head`. However, the problem is complicated by the need to keep track of <i>carries</i>. Here\\'s how we deal with it. After adding two digits together:\\n\\n- The <i>non-carry</i> part is obtained by doing `total % 10`. By taking the remainder of a number after dividing by 10, we only get what\\'s left in the ones place. For example, if the total is 15, then 15 % 10 = 5, so we create a new ListNode with value 5 and link it to `head`\\n- The <i>carry</i> is obtained by doing `total // 10` (floor division by 10). By dividing by 10 and rounding down, we get the carry value. So 15 // 10 = 1 (1.5 rounded down is 1) so that corresponds to a carry of 1.\\n\\nWe then keep repeating this until all lists have reached the end AND there are no more carry values. At the end, `head.next`holds the very first node of our answer, so we return `head.next`.\\n\\n# Code\\n```\\n# Definition for singly-linked list.\\n# class ListNode(object):\\n# def __init__(self, val=0, next=None):\\n# self.val = val\\n# self.next = next\\nclass Solution(object):\\n def addTwoNumbers(self, l1, l2):\\n head = ListNode()\\n current = head\\n carry = 0\\n while (l1 != None or l2 != None or carry != 0):\\n l1_value = l1.val if l1 else 0\\n l2_value = l2.val if l2 else 0\\n total = l1_value + l2_value + carry\\n current.next = ListNode(total % 10)\\n carry = total // 10\\n # Move list pointers forward\\n l1 = l1.next if l1 else None\\n l2 = l2.next if l2 else None\\n current = current.next\\n return head.next\\n```"
6
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 ...
null
(PYTHON) In-Place, O(N) 90%+ Speed, 60%+ Space. Easy to Understand.
add-two-numbers
0
1
# Intuition\nFor each pair of Nodes in l1 and l2, find their "raw" sum along with the carryover. Use modulo to get the digit and floor division to get the carry over. Then connect the remainder of l2 to the end of l1 (if it is longer). Continue the original process, ommiting the l2.val sum. \n\n# Complexity\n- Time com...
3
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 ...
null
Python Code For Beginners Full Recursion
add-two-numbers
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 ...
null
Python 99.90 % beats || Easy Solution
add-two-numbers
0
1
# Your upvote is my motivation!\n\n\n# Code\n```\n# Definition for singly-linked list.\n# Definition for singly-linked list.\nclass ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\nclass Solution:\n def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[Li...
18
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 ...
null
2. Add Two Numbers
add-two-numbers
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 ...
null
✅Mastering Adding Two Number 💡 Beginner's Guide
add-two-numbers
1
1
# Adding Two Numbers - LeetCode Problem #2\n---\n---\n\n## \uD83D\uDCA1Approach 1: Recursive Approach\n---\n\n### \u2728Explanation\nIn this approach, we recursively traverse both linked lists `l1` and `l2`, adding their corresponding nodes and handling carry if necessary. We create a new linked list `p` to store the s...
3
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 ...
null
Easy way of suming for pyhton
add-two-numbers
0
1
# Intuition\n<!-- Transfer to int and then back to linked list -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n`...
0
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 ...
null
listNode, newNode
add-two-numbers
0
1
# Code\n```\nclass ListNode:\n def __init__(self, val=0, next=None):\n self.val = val\n self.next = next\nclass Solution:\n def addTwoNumbers(self, l1: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]:\n dummy = ListNode(0)\n curr = dummy\n carry = 0\n wh...
0
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 ...
null
Easy | Solution | Python |Linked List
add-two-numbers
0
1
# Code\n```\n# Definition for singly-linked list.\n# class ListNode:\n# def __init__(self, val=0, next=None):\n# self.val = val\n# self.next = next\nclass Solution:\n def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode:\n d = n = ListNode(0)\n num1 = num2 = ""\n w...
59
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 ...
null
100% Beats | Java | C++ | Python | Javascript | C# | PHP
add-two-numbers
1
1
\n### steps\n1. Initialize a dummy node and a current node to keep track of the result linked list.\n2. Initialize carry to 0.\n3. Traverse both input linked lists simultaneously.\n4. At each step, calculate the sum of the current nodes\' values along with the carry.\n5. Calculate the carry for the next iteration as su...
19
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 ...
null
✅Python3 78ms memory efficient🔥🔥
add-two-numbers
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n**Normal list traversal and adding numbers.**\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- we used **yield** here because it\'s very memory efficient.\n- forward function used to get in-sequence value of linke...
3
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 ...
null
Beginner | Simple | Python Solution 😁
add-two-numbers
0
1
# *Intuition*\n<!-- Describe your first thoughts on how to solve this problem. -->\n- *We get numbers and add them.*\n# *Approach*\n<!-- Describe your approach to solving the problem. -->\n- *The first thing that comes to mind is that we must obtain the numbers from both lists so that we may utilise them for addition l...
2
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 ...
null
Easy step by step solution
add-two-numbers
0
1
\n# Approach\n1. Firstly, get all the elements from both LL\n2. Reverse those numbers\n3. Convert them from array to two numbers\n4. Convert the sum of those numbers to array of digits\n5. Create new LL from that array of digits\n\nHope you find it useful and if so, please upvote, cause it`s my first solution\n\n# Comp...
2
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 ...
null
Represented as linked lists
add-two-numbers
0
1
# Intuition\nwe need to perform addition similarly to how we add numbers manually, taking care of carrying values when the sum exceeds 9\n\n# Approach\n1. Initialize a dummy node and a pointer current to keep track of the current node in the result linked list.\n\n2. Start iterating through both input linked lists (l1 ...
2
You are given two **non-empty** linked lists representing two non-negative integers. The digits are stored in **reverse order**, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 ...
null
✅3 Method's || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥
longest-substring-without-repeating-characters
1
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind the 3 solutions is to iteratively find the longest substring without repeating characters by maintaining a sliding window approach. We use two pointers (`left` and `right`) to represent the boundaries of the current s...
818
Given a string `s`, find the length of the **longest** **substring** without repeating characters. **Example 1:** **Input:** s = "abcabcbb " **Output:** 3 **Explanation:** The answer is "abc ", with the length of 3. **Example 2:** **Input:** s = "bbbbb " **Output:** 1 **Explanation:** The answer is "b ", with t...
null
[VIDEO] Step-by-Step Visualization of Sliding Window
longest-substring-without-repeating-characters
0
1
https://youtu.be/pY2dYa1m2VM\n\nA brute force solution would first require finding every possible substring, which would run in O(n<sup>2</sup>) time. We\'re not done yet though, because we now have to check every substring for duplicate characters by iterating through every substring. Each check for duplicate charac...
6
Given a string `s`, find the length of the **longest** **substring** without repeating characters. **Example 1:** **Input:** s = "abcabcbb " **Output:** 3 **Explanation:** The answer is "abc ", with the length of 3. **Example 2:** **Input:** s = "bbbbb " **Output:** 1 **Explanation:** The answer is "b ", with t...
null
[Python3]: sliding window O(N) with explanation
longest-substring-without-repeating-characters
0
1
**Sliding window**\nWe use a dictionary to store the character as the key, the last appear index has been seen so far as value.\nseen[charactor] = index\n\n move the pointer when you met a repeated character in your window.\n\n\t \n```\nindext 0 1 2 3 4 5 6 7\nstring a c b d b a c...
819
Given a string `s`, find the length of the **longest** **substring** without repeating characters. **Example 1:** **Input:** s = "abcabcbb " **Output:** 3 **Explanation:** The answer is "abc ", with the length of 3. **Example 2:** **Input:** s = "bbbbb " **Output:** 1 **Explanation:** The answer is "b ", with t...
null
👾C#,Java,Python3, JavaScript Solutions (easy)
longest-substring-without-repeating-characters
1
1
See Code and Explanation : **\u2B50[https://zyrastory.com/en/coding-en/leetcode-en/leetcode-3-longest-substring-without-repeating-characters-solution-and-explanation-en/](https://zyrastory.com/en/coding-en/leetcode-en/leetcode-3-longest-substring-without-repeating-characters-solution-and-explanation-en/)\u2B50**\n\n**...
7
Given a string `s`, find the length of the **longest** **substring** without repeating characters. **Example 1:** **Input:** s = "abcabcbb " **Output:** 3 **Explanation:** The answer is "abc ", with the length of 3. **Example 2:** **Input:** s = "bbbbb " **Output:** 1 **Explanation:** The answer is "b ", with t...
null
#Python(🐍) Easy solution O(n)
longest-substring-without-repeating-characters
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
Given a string `s`, find the length of the **longest** **substring** without repeating characters. **Example 1:** **Input:** s = "abcabcbb " **Output:** 3 **Explanation:** The answer is "abc ", with the length of 3. **Example 2:** **Input:** s = "bbbbb " **Output:** 1 **Explanation:** The answer is "b ", with t...
null
Simple Python3 Solution using Sliding window || Beats 99% || 💻🧑‍💻🤖
longest-substring-without-repeating-characters
0
1
\n\n# Code\n```\nclass Solution:\n def lengthOfLongestSubstring(self, s: str) -> int:\n l=len(s)\n if l==0:\n return 0\n dicts={}\n max_len=0\n start=0\n for i in range(l):\n if s[i] in dicts and start<=dicts[s[i]]:\n start = dicts[s[i]]+...
25
Given a string `s`, find the length of the **longest** **substring** without repeating characters. **Example 1:** **Input:** s = "abcabcbb " **Output:** 3 **Explanation:** The answer is "abc ", with the length of 3. **Example 2:** **Input:** s = "bbbbb " **Output:** 1 **Explanation:** The answer is "b ", with t...
null
Simple Explanation | Concise | Thinking Process & Example
longest-substring-without-repeating-characters
0
1
Lets start with the following example: \n\n**Assume you had no repeating characters** (In below example, just look at *first three* characters)\n\nWe take two pointers, `l` and `r`, both starting at `0`. At every iteration, we update the longest string with non-repeating characters found = `r-l+1` and just keep a note ...
348
Given a string `s`, find the length of the **longest** **substring** without repeating characters. **Example 1:** **Input:** s = "abcabcbb " **Output:** 3 **Explanation:** The answer is "abc ", with the length of 3. **Example 2:** **Input:** s = "bbbbb " **Output:** 1 **Explanation:** The answer is "b ", with t...
null
🔥🔥🔥 python3 Easy ( Sliding window Technique )🔥🔥🔥
longest-substring-without-repeating-characters
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
9
Given a string `s`, find the length of the **longest** **substring** without repeating characters. **Example 1:** **Input:** s = "abcabcbb " **Output:** 3 **Explanation:** The answer is "abc ", with the length of 3. **Example 2:** **Input:** s = "bbbbb " **Output:** 1 **Explanation:** The answer is "b ", with t...
null
beats 99.72% on time and 88.23% on space
longest-substring-without-repeating-characters
0
1
# Approach\n\nUse a two-pointer approach and maintain a set of unique characters between the two pointers. iterate through string, checking if the next char is unique or not. If it\'s unique, add it to unique chars and advance the leading index. Otherwise, advance the trailing index until the unique chars set is exclus...
0
Given a string `s`, find the length of the **longest** **substring** without repeating characters. **Example 1:** **Input:** s = "abcabcbb " **Output:** 3 **Explanation:** The answer is "abc ", with the length of 3. **Example 2:** **Input:** s = "bbbbb " **Output:** 1 **Explanation:** The answer is "b ", with t...
null
Beats 98.7%✅ | O( O(n^2 )✅ | Python (Step by step explanation)
longest-substring-without-repeating-characters
0
1
# Intuition\nThe problem requires finding the length of the longest substring without repeating characters in a given string. We can approach this by using a sliding window technique to keep track of the current substring without repeating characters and update the maximum length found so far.\n\n# Approach\n1. Initial...
2
Given a string `s`, find the length of the **longest** **substring** without repeating characters. **Example 1:** **Input:** s = "abcabcbb " **Output:** 3 **Explanation:** The answer is "abc ", with the length of 3. **Example 2:** **Input:** s = "bbbbb " **Output:** 1 **Explanation:** The answer is "b ", with t...
null
Sliding Window Approach (Runtime - beats 94.47%) | Time Complexity O(n)
longest-substring-without-repeating-characters
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe intuition behind this code is to use a sliding window approach to maintain a substring that doesn\'t contain repeating characters. By keeping track of the most recent index where each character appeared, the algorithm can efficiently ...
4
Given a string `s`, find the length of the **longest** **substring** without repeating characters. **Example 1:** **Input:** s = "abcabcbb " **Output:** 3 **Explanation:** The answer is "abc ", with the length of 3. **Example 2:** **Input:** s = "bbbbb " **Output:** 1 **Explanation:** The answer is "b ", with t...
null
Easy well explained python solution (faster than 98%), O(n) time complexity
longest-substring-without-repeating-characters
0
1
# Intuition\nwe use a **starting point** while iterating over the given string and every time we find a repeated character we calculate the length of the substring between the starting point and the current point - 1.\nevery time we find a repetition we set the starting point to the character next to the last occurrenc...
12
Given a string `s`, find the length of the **longest** **substring** without repeating characters. **Example 1:** **Input:** s = "abcabcbb " **Output:** 3 **Explanation:** The answer is "abc ", with the length of 3. **Example 2:** **Input:** s = "bbbbb " **Output:** 1 **Explanation:** The answer is "b ", with t...
null
✅ [video walkthrough] 🔥 Readable code explained by FAANG engineer
median-of-two-sorted-arrays
0
1
I made a super detailed video walkthrough, since this is a really tough question \uD83D\uDE42 \nPlease upvote if you find this helpful!\n\nhttps://youtu.be/QjrchMRAkew\n\nCode:\n```\nclass Solution:\n def findMedianSortedArrays(self, nums1, nums2):\n if len(nums1) > len(nums2):\n nums1, nums2 = num...
59
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))`. **Example 1:** **Input:** nums1 = \[1,3\], nums2 = \[2\] **Output:** 2.00000 **Explanation:** merged array = \[1,2,3\] and median is ...
null
✅99%🔥||✅Journey From Brute Force to Most 🔥Optimized ✅Three Approaches||🔥Easy to understand
median-of-two-sorted-arrays
1
1
# Problem Understanding:\nIn simpler terms, you need to **find the middle value of the combined**, sorted array formed by merging nums1 and nums2. If the combined **array has an even number** of elements, you should return the average of the two middle values. **If it has an odd number of elements, you should return th...
802
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))`. **Example 1:** **Input:** nums1 = \[1,3\], nums2 = \[2\] **Output:** 2.00000 **Explanation:** merged array = \[1,2,3\] and median is ...
null
🔥99% || Super easy🔥👌
median-of-two-sorted-arrays
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. Combine the two input arrays \'nums1\' and \'nums2\' into a single array named \'nums\'.\n2. Sort the combined array \'nums\' in ascending order.\n3. Determine the length of the sorted array \'nums\'.\n4. If the length \'...
1
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))`. **Example 1:** **Input:** nums1 = \[1,3\], nums2 = \[2\] **Output:** 2.00000 **Explanation:** merged array = \[1,2,3\] and median is ...
null
Median of Two Sorted Arrays | Optimal Code | Python |
median-of-two-sorted-arrays
0
1
# Complexity\n- Time complexity: $$O(log(n + m))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:\n n...
1
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))`. **Example 1:** **Input:** nums1 = \[1,3\], nums2 = \[2\] **Output:** 2.00000 **Explanation:** merged array = \[1,2,3\] and median is ...
null
✅ 94.96% Binary Search & Two Pointers
median-of-two-sorted-arrays
1
1
# Comprehensive Guide to Solving "Median of Two Sorted Arrays"\n\n## Introduction & Problem Statement\n\n"Median of Two Sorted Arrays" is a classic problem that tests one\'s algorithmic depth and understanding of binary search and two-pointer techniques. The challenge is to find the median of two sorted arrays, `nums1`...
74
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))`. **Example 1:** **Input:** nums1 = \[1,3\], nums2 = \[2\] **Output:** 2.00000 **Explanation:** merged array = \[1,2,3\] and median is ...
null
🚩📈99.99% Acceptance with Optimised Solution | ✅Explained in Detail🔥
median-of-two-sorted-arrays
1
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe median of two sorted arrays is essentially the middle element of the combined sorted array. To find it efficiently, we can use a binary search approach to partition both arrays in such a way that the elements on the left side are smal...
3
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))`. **Example 1:** **Input:** nums1 = \[1,3\], nums2 = \[2\] **Output:** 2.00000 **Explanation:** merged array = \[1,2,3\] and median is ...
null
My thought process - O(log(min(N, M))) time, O(1) space - Python, JavaScript, Java, C++
median-of-two-sorted-arrays
1
1
# Intuition\nWelcome to my article! This starts with `What is median?`. Understanding `median` is a key to solve this quesiton.\n\n---\n\n# Solution Video\n\nToday, I\'m going on business trip. This article is written in a train. lol\nIf I have a time tonight, I will create a solution video for this question.\n\nInstea...
34
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))`. **Example 1:** **Input:** nums1 = \[1,3\], nums2 = \[2\] **Output:** 2.00000 **Explanation:** merged array = \[1,2,3\] and median is ...
null
🔥🔥🔥🔥🔥Easy Solution , Simple Method🔥🔥🔥🔥🔥
median-of-two-sorted-arrays
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
3
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))`. **Example 1:** **Input:** nums1 = \[1,3\], nums2 = \[2\] **Output:** 2.00000 **Explanation:** merged array = \[1,2,3\] and median is ...
null
🚀100% || Two Solutions || Two Pointers & Divide And Conquer || Commented Code🚀
median-of-two-sorted-arrays
1
1
# Problem Description\nGiven two sorted arrays, `nums1` and `nums2`, each of sizes `M` and `N` respectively. The **goal** is to find the **median** of the **combined** array formed by merging `nums1` and `nums2`.\n\nThe **task** is to design an algorithm with an overall run time complexity of `O(log(min(m, n)))` to cal...
22
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))`. **Example 1:** **Input:** nums1 = \[1,3\], nums2 = \[2\] **Output:** 2.00000 **Explanation:** merged array = \[1,2,3\] and median is ...
null
✅Mastering Finding Median in Sorted Arrays 💡 Beginner's Guide
median-of-two-sorted-arrays
1
1
# \u2753 Finding Median in Sorted Arrays \u2753\n\n## \uD83D\uDCA1Approach 1: Brute Force\n\n### \u2728Explanation\nThe brute force approach involves merging two sorted arrays into a single array and then calculating the median based on the length of the merged array. This method has a time complexity of O((N + M) * lo...
2
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))`. **Example 1:** **Input:** nums1 = \[1,3\], nums2 = \[2\] **Output:** 2.00000 **Explanation:** merged array = \[1,2,3\] and median is ...
null
median of two sorted arrays
median-of-two-sorted-arrays
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
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))`. **Example 1:** **Input:** nums1 = \[1,3\], nums2 = \[2\] **Output:** 2.00000 **Explanation:** merged array = \[1,2,3\] and median is ...
null
Find the Median of Sorted List || Python || Easy Solution || Beats 90.40 %
median-of-two-sorted-arrays
0
1
\n# Algorithm\n<!-- Describe your approach to solving the problem. -->\n1. Merge the given lists.\n````\nnums1.extend(nums2)\n````\n2. Now sort the merged list.\n````\nnums1.sort()\n````\n3. Find the middle element of the sorted list.\n```\nmid = len(nums1)//2\n```\n4. If the length of the sorted list is even : \n```\n...
2
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))`. **Example 1:** **Input:** nums1 = \[1,3\], nums2 = \[2\] **Output:** 2.00000 **Explanation:** merged array = \[1,2,3\] and median is ...
null
✅ Beats 96.49% 🔥 || 5 Different Approaches 💡 || Brute Force || EAC || DP || MA || Recursion ||
longest-palindromic-substring
1
1
### It takes a lot of efforts to write such long explanatinon, so please UpVote \u2B06\uFE0F if this helps you.\n\n# Approach 1: Brute Force\n\n![image.png](https://assets.leetcode.com/users/images/78b06edf-2497-4fad-bc79-f94571e74384_1698375305.7151458.png)\n\n# Intuition :\n\n**The obvious brute force solution is to ...
350
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
✅ Beats 96.49% 🔥 || 5 Different Approaches 💡 || Brute Force || EAC || DP || MA || Recursion ||
longest-palindromic-substring
1
1
### It takes a lot of efforts to write such long explanatinon, so please UpVote \u2B06\uFE0F if this helps you.\n\n# Approach 1: Brute Force\n\n![image.png](https://assets.leetcode.com/users/images/78b06edf-2497-4fad-bc79-f94571e74384_1698375305.7151458.png)\n\n# Intuition :\n\n**The obvious brute force solution is to ...
350
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
🔥 Easy solution | JAVA | Python 3 🔥| Manacher's algorithm |
longest-palindromic-substring
1
1
# Intuition\nUsing Manacher\'s algorithm to find the longest palindromic substring efficiently. \n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. String Transformation: The input string \'s\' is transformed into a new string \'modified_s\' by inserting special characters (\'#\') be...
1
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
🔥 Easy solution | JAVA | Python 3 🔥| Manacher's algorithm |
longest-palindromic-substring
1
1
# Intuition\nUsing Manacher\'s algorithm to find the longest palindromic substring efficiently. \n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n1. String Transformation: The input string \'s\' is transformed into a new string \'modified_s\' by inserting special characters (\'#\') be...
1
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
Longest Palindrome
longest-palindromic-substring
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
Longest Palindrome
longest-palindromic-substring
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
1
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
Rust 3ms / Python: simple quadratic solution with explanation
longest-palindromic-substring
0
1
# Intuition\nThere is a linear solution which is called [Manacher algorithm](https://cp-algorithms.com/string/manacher.html). But it is hard to come up with this during the interview.\n\nA very straight forward is a $O(n^2)$ algorihtm in which you try every position and try to expand the string as far as possible. Here...
1
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
Rust 3ms / Python: simple quadratic solution with explanation
longest-palindromic-substring
0
1
# Intuition\nThere is a linear solution which is called [Manacher algorithm](https://cp-algorithms.com/string/manacher.html). But it is hard to come up with this during the interview.\n\nA very straight forward is a $O(n^2)$ algorihtm in which you try every position and try to expand the string as far as possible. Here...
1
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
Daily Leetcoding Challenge 27Beginner Friendly Approach. Understandable.Full Explained 100% working.
longest-palindromic-substring
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWhat I thought was basic palindrome solution which we do write.Thought of creating a list which will store the the longest palindromic substring. Here is the Approach\n\n# Beginner Friendly Approach\n<!-- Describe your approach to solving...
1
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
Daily Leetcoding Challenge 27Beginner Friendly Approach. Understandable.Full Explained 100% working.
longest-palindromic-substring
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWhat I thought was basic palindrome solution which we do write.Thought of creating a list which will store the the longest palindromic substring. Here is the Approach\n\n# Beginner Friendly Approach\n<!-- Describe your approach to solving...
1
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
[VIDEO] Visualization of "Expand From Centers" Solution
longest-palindromic-substring
0
1
https://youtu.be/E-tmN1OM9aA\n\nA brute force solution would first require generating every possible substring, which runs in O(n<sup>2</sup>) time. Then, <i>for each</i> of those substrings, we have to check if they are a palindrome. Since palindromes read the same forwards and backwards, we know that they have to b...
6
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
[VIDEO] Visualization of "Expand From Centers" Solution
longest-palindromic-substring
0
1
https://youtu.be/E-tmN1OM9aA\n\nA brute force solution would first require generating every possible substring, which runs in O(n<sup>2</sup>) time. Then, <i>for each</i> of those substrings, we have to check if they are a palindrome. Since palindromes read the same forwards and backwards, we know that they have to b...
6
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
【Video】Give me 10 minutes - How we think about a solution - Python, JavaScript, Java, C++
longest-palindromic-substring
1
1
# Intuition\nUsing two pointers\n\n---\n\n# Solution Video\n\nhttps://youtu.be/aMH1eomKCmE\n\n\u25A0 Timeline of the video\n`0:04` How did you find longest palindromic substring?\n`0:59` What is start point?\n`1:44` Demonstrate how it works with odd case\n`4:36` How do you calculate length of palindrome we found?\n`7:3...
33
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
【Video】Give me 10 minutes - How we think about a solution - Python, JavaScript, Java, C++
longest-palindromic-substring
1
1
# Intuition\nUsing two pointers\n\n---\n\n# Solution Video\n\nhttps://youtu.be/aMH1eomKCmE\n\n\u25A0 Timeline of the video\n`0:04` How did you find longest palindromic substring?\n`0:59` What is start point?\n`1:44` Demonstrate how it works with odd case\n`4:36` How do you calculate length of palindrome we found?\n`7:3...
33
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
🔥Expand Around Center & 🔥100% Manacher's Algorithm | Java | C++ | Py | Js| C# | PHP
longest-palindromic-substring
1
1
# 1st Method :- Expand Around Center \uD83D\uDEA9\n## Intuition \uD83D\uDE80:\n\nThe intuition behind this code is to find the longest palindromic substring within a given input string `s`. A palindromic substring is a string that reads the same forwards and backward. To achieve this, the code explores the input string...
45
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
🔥Expand Around Center & 🔥100% Manacher's Algorithm | Java | C++ | Py | Js| C# | PHP
longest-palindromic-substring
1
1
# 1st Method :- Expand Around Center \uD83D\uDEA9\n## Intuition \uD83D\uDE80:\n\nThe intuition behind this code is to find the longest palindromic substring within a given input string `s`. A palindromic substring is a string that reads the same forwards and backward. To achieve this, the code explores the input string...
45
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
✅ 98.55% Manacher's algorithm
longest-palindromic-substring
1
1
# Intuition\nWhen tackling the problem of finding the longest palindromic substring, one might initially think of generating all possible substrings and checking each for palindromicity. However, this approach is inefficient. A more nuanced understanding would lead us to the realization that for each character in the s...
37
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
✅ 98.55% Manacher's algorithm
longest-palindromic-substring
1
1
# Intuition\nWhen tackling the problem of finding the longest palindromic substring, one might initially think of generating all possible substrings and checking each for palindromicity. However, this approach is inefficient. A more nuanced understanding would lead us to the realization that for each character in the s...
37
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
Python Solution : with detailed explanation : using DP
longest-palindromic-substring
0
1
#### Approach (implemented Dp rules)\n* ##### Definition : the row and col in the dp table represent the slicing index on the string s (inclusive)\n* ##### example s = \'babad\' -- > dp[2][3] = s[2:3] = ba\n##### Steps : \n* ##### Fill the diagonal with True, b/c e...
722
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
Python Solution : with detailed explanation : using DP
longest-palindromic-substring
0
1
#### Approach (implemented Dp rules)\n* ##### Definition : the row and col in the dp table represent the slicing index on the string s (inclusive)\n* ##### example s = \'babad\' -- > dp[2][3] = s[2:3] = ba\n##### Steps : \n* ##### Fill the diagonal with True, b/c e...
722
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
🔥🚀Beats 99.90%🚀 | 🔥🚩Optimised Code | 🧭O(n^2) Time & O(1) Space |🔥 Using Dynamic Programming🔥
longest-palindromic-substring
1
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe given code is an implementation of the "Expand Around Center" approach for finding the longest palindromic substring in a given string. This approach works by iterating through each character in the string and expanding around it to c...
20
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
🔥🚀Beats 99.90%🚀 | 🔥🚩Optimised Code | 🧭O(n^2) Time & O(1) Space |🔥 Using Dynamic Programming🔥
longest-palindromic-substring
1
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe given code is an implementation of the "Expand Around Center" approach for finding the longest palindromic substring in a given string. This approach works by iterating through each character in the string and expanding around it to c...
20
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
"Expand Around Center" Approach to Finding the Longest Palindromic Substring.
longest-palindromic-substring
0
1
# **Intuition**\nWe can use the "Expand Around Center" approach to find the longest palindromic substring. \n\nThe idea is to treat each character as a potential center of a palindrome and expand outwards while checking if the characters on both sides match. \n\n---\n\n## **Approach**\n1. Initialize variables to keep t...
2
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
"Expand Around Center" Approach to Finding the Longest Palindromic Substring.
longest-palindromic-substring
0
1
# **Intuition**\nWe can use the "Expand Around Center" approach to find the longest palindromic substring. \n\nThe idea is to treat each character as a potential center of a palindrome and expand outwards while checking if the characters on both sides match. \n\n---\n\n## **Approach**\n1. Initialize variables to keep t...
2
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
✅Unlocking Palindromic Mastery: Leetcode Algorithmic Gems ✅3 Solution💡Beginner's Guide by Mr.Robot
longest-palindromic-substring
1
1
### Welcome to the Blog you need to be a Pro-bro in this Problem\n---\n## \uD83D\uDCA1Approach 1: Middle Expansion - Explained in Depth\n\n### \u2728Explanation\nThe Middle Expansion approach is an intuitive method for finding the longest palindromic substring. The idea is to consider each character in the string as a ...
1
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
✅Unlocking Palindromic Mastery: Leetcode Algorithmic Gems ✅3 Solution💡Beginner's Guide by Mr.Robot
longest-palindromic-substring
1
1
### Welcome to the Blog you need to be a Pro-bro in this Problem\n---\n## \uD83D\uDCA1Approach 1: Middle Expansion - Explained in Depth\n\n### \u2728Explanation\nThe Middle Expansion approach is an intuitive method for finding the longest palindromic substring. The idea is to consider each character in the string as a ...
1
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
python3
longest-palindromic-substring
0
1
\n# Complexity\n- Time complexity:\n- O(N^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n- O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def longestPalindrome(self, s: str) -> str:\n n=len(s)\n m="" \n def...
2
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
python3
longest-palindromic-substring
0
1
\n# Complexity\n- Time complexity:\n- O(N^2)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n- O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n def longestPalindrome(self, s: str) -> str:\n n=len(s)\n m="" \n def...
2
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
✅☑[C++/Java/Python/JavaScript] || 4 Approaches || EXPLAINED🔥
longest-palindromic-substring
1
1
# PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n**(Also explained in the code)**\n\n#### ***Approach 1(Brute Approach)***\n1. The `longestPalindrome` function is the main function for finding the longest palindromic substring.\n\n1. It first preprocesses the input string `s` to create a new string `sPrime` that ...
3
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
✅☑[C++/Java/Python/JavaScript] || 4 Approaches || EXPLAINED🔥
longest-palindromic-substring
1
1
# PLEASE UPVOTE IF IT HELPED\n\n---\n\n\n# Approaches\n**(Also explained in the code)**\n\n#### ***Approach 1(Brute Approach)***\n1. The `longestPalindrome` function is the main function for finding the longest palindromic substring.\n\n1. It first preprocesses the input string `s` to create a new string `sPrime` that ...
3
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
✅ Python Solution | Dynamic Programming
longest-palindromic-substring
0
1
# Intuition\n- Using DP\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n- Using 2D list\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n^2)$$\n<!...
0
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
✅ Python Solution | Dynamic Programming
longest-palindromic-substring
0
1
# Intuition\n- Using DP\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n- Using 2D list\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(n^2)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n^2)$$\n<!...
0
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
5. Longest Palindromic Substring
longest-palindromic-substring
0
1
# Intuition:\nTo find the longest palindromic substring, the approach considers expanding around each character in the given string `s` to find both odd and even-length palindromes. It aims to optimize the search process by comparing substrings around the potential centers.\n\n# Approach:\n1. Initialize `start` and `ma...
0
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
5. Longest Palindromic Substring
longest-palindromic-substring
0
1
# Intuition:\nTo find the longest palindromic substring, the approach considers expanding around each character in the given string `s` to find both odd and even-length palindromes. It aims to optimize the search process by comparing substrings around the potential centers.\n\n# Approach:\n1. Initialize `start` and `ma...
0
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
Commented and Readable Python Solution with O(1) Space
longest-palindromic-substring
0
1
```\nclass Solution:\n def longestPalindrome(self, s: str) -> str:\n n=len(s)\n #for storing the maximum pallindromic substr length\n max_length=0\n begin=0\n end=0\n for i in range(n):\n #pallindromic string can be of two types odd or even \n \n ...
1
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end ...
Commented and Readable Python Solution with O(1) Space
longest-palindromic-substring
0
1
```\nclass Solution:\n def longestPalindrome(self, s: str) -> str:\n n=len(s)\n #for storing the maximum pallindromic substr length\n max_length=0\n begin=0\n end=0\n for i in range(n):\n #pallindromic string can be of two types odd or even \n \n ...
1
Given a string `s`, return _the longest_ _palindromic_ _substring_ in `s`. **Example 1:** **Input:** s = "babad " **Output:** "bab " **Explanation:** "aba " is also a valid answer. **Example 2:** **Input:** s = "cbbd " **Output:** "bb " **Constraints:** * `1 <= s.length <= 1000` * `s` consist of only dig...
How can we reuse a previously computed palindrome to compute a larger palindrome? If “aba” is a palindrome, is “xabax” a palindrome? Similarly is “xabay” a palindrome? Complexity based hint: If we use brute-force and check whether for every start and end position a substring is a palindrome we have O(n^2) start - end p...
[VIDEO] Step-by-Step Visualization of O(n) Solution
zigzag-conversion
0
1
https://youtu.be/ytSl-K4xo3w\n\nThe key to solving this problem is to understand that we assign characters to rows by <i>oscillating</i> between the top and bottom rows. In other words, if we traversed the string and looked at which row each character belonged to (let\u2019s say numRows is 3), the pattern would be 1 2...
17
The string `"PAYPALISHIRING "` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: `"PAHNAPLSIIGYIR "` Write the code that will take a string and make this co...
null
O(n) Solution with Approaches
zigzag-conversion
0
1
# Intuition\nFor the Row R and the zigzag N, the character need to be extract is s[R + N * (total number of characters in a zigzag)] and s[-R + (N + 1) * (total number of characters in a zigzag)]\n\n# Approach\n1 Calculate how many time the sigzag repeats(steps).\n2 Generate result string from the characters in the fir...
2
The string `"PAYPALISHIRING "` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: `"PAHNAPLSIIGYIR "` Write the code that will take a string and make this co...
null
ZigZag Conversion Decoded! 🔄✨ Code in C++, Java, Python, C#, JS 🚀
zigzag-conversion
1
1
# \u2753ZigZag Conversion\u2753\n---\n\n## \uD83D\uDCA1Approach 1: ZigZag Pattern\n\n### \u2728Explanation\nThe solution utilizes the zigzag pattern to convert the input string. It initializes a vector of strings representing each row and iterates through the input string, placing characters in the corresponding rows b...
2
The string `"PAYPALISHIRING "` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: `"PAHNAPLSIIGYIR "` Write the code that will take a string and make this co...
null
Easy Explanation with Pics and Video | Java C++ Python
zigzag-conversion
1
1
![image](https://assets.leetcode.com/users/images/fdf22375-8354-4cb7-adb0-cef316e39a2d_1675385332.2793877.png)\n\n\nThings become clear with the above image.\n\n# Intuition:\n1. Just look at the top row what is the difference b/w each char i.e A and I and I and Q = 8\n 5*2-2 == numberOf rows *2 - 2 (The corn...
96
The string `"PAYPALISHIRING "` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: `"PAHNAPLSIIGYIR "` Write the code that will take a string and make this co...
null
6. Zigzag Conversion || Solution for Python3
zigzag-conversion
0
1
```\nclass Solution:\n def convert(self, s: str, numRows: int) -> str:\n res, unit = "", numRows * 2 - 2\n if numRows == 1:\n return s \n for r in range(numRows):\n for n in range(len(s)):\n if r == 0 or r == numRows - 1:\n if unit * n +...
2
The string `"PAYPALISHIRING "` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: `"PAHNAPLSIIGYIR "` Write the code that will take a string and make this co...
null
Simple O(n) Python Solution for Zigzag Strings
zigzag-conversion
0
1
# Intuition\nThink of it like bouncing a ball: it goes down, hits the floor, and bounces back up. This is like our zigzag pattern with the string.\n\n# Approach\n1. If we only have one row or more rows than letters, just give back the original word.\n2. I used a jump thing to know if I should go up or down. If I\'m at ...
7
The string `"PAYPALISHIRING "` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: `"PAHNAPLSIIGYIR "` Write the code that will take a string and make this co...
null
Python3 50ms 🔥very simple solution: Detailed Explained🔥🔥🔥
zigzag-conversion
0
1
# Intuition\n**![Capture.PNG](https://assets.leetcode.com/users/images/c777de6f-78d4-4daa-b97d-14a9b04c4ae0_1675446391.282558.png)**\n<!-- Describe your first thoughts on how to solve this problem. -->\n**Zig-zag traversal is simple level order string traversal.**\n# Approach\n<!-- Describe your approach to solving the...
4
The string `"PAYPALISHIRING "` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: `"PAHNAPLSIIGYIR "` Write the code that will take a string and make this co...
null
Python code : 59ms beats(86.35%) : with brief explanation
zigzag-conversion
0
1
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo create a 2d list with number of sublists equal to that of numRows where each sublist contains the letter from each rows of the input respectively.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nbasically we take ...
3
The string `"PAYPALISHIRING "` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: `"PAHNAPLSIIGYIR "` Write the code that will take a string and make this co...
null
Very simple and intuitive O(n) python solution with explanation
zigzag-conversion
0
1
In this question the most important thing is getting the pattern correct. It is very easy to go down the wrong path and spend 10 minutes trying to figure out how to make a complicated algorithm work when a very easy one would suffice.\n\n> Thinking process\n\n1. First I looked at the problem and thought about how the p...
171
The string `"PAYPALISHIRING "` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: `"PAHNAPLSIIGYIR "` Write the code that will take a string and make this co...
null
100 % ✔️ Solution Explained with visualization to the code
zigzag-conversion
1
1
[https://youtu.be/EWZWiG750FI]()
51
The string `"PAYPALISHIRING "` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: `"PAHNAPLSIIGYIR "` Write the code that will take a string and make this co...
null
Python | well Explanation | Simple | Easy ✅✅
zigzag-conversion
0
1
![explanision.PNG](https://assets.leetcode.com/users/images/39ed3cd5-0c1e-4353-af74-777a021ecdcb_1675392805.2104511.png)\nI solved this problem using index of each character in string `s`\n### The first and last rows:\nI find sequence of numbers that, each element is greater than the one before it by 6 (add) `2*numRow...
4
The string `"PAYPALISHIRING "` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G Y I R And then read line by line: `"PAHNAPLSIIGYIR "` Write the code that will take a string and make this co...
null