Dataset Viewer
Auto-converted to Parquet Duplicate
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
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
38