question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | CPP solution using brute force. | cpp-solution-using-brute-force-by-ankurk-f05p | IntuitionBrute forceApproachMake all the pairs of happy string using recursion and return the k'th (index k-1) string in vector if vector is big enough else ret | ankurkarn | NORMAL | 2025-02-19T13:25:26.356754+00:00 | 2025-02-19T13:25:26.356754+00:00 | 19 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Brute force
# Approach
<!-- Describe your approach to solving the problem. -->
Make all the pairs of happy string using recursion and return the k'th (index k-1) string in vector if vector is big enough else return empty string.
# Complexit... | 2 | 0 | ['C++'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Simplest solution with Explaination in O(N) & 100% beats | simplest-solution-with-explaination-in-o-8rd0 | IntuitionThe problem involves generating the k-th lexicographically smallest "happy string" of lengthn. A "happy string" is one that adheres to the following co | patel_jaimin | NORMAL | 2025-02-19T12:11:32.125870+00:00 | 2025-02-19T12:11:32.125870+00:00 | 117 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem involves generating the k-th lexicographically smallest "happy string" of length `n`. A "happy string" is one that adheres to the following constraints:
- The string consists only of characters `'a'`, `'b'`, and `'c'`.
- No two... | 2 | 0 | ['C', 'Python', 'C++', 'Java', 'Go', 'TypeScript', 'Python3', 'JavaScript', 'C#', 'Dart'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Most Optimal Approach TC- O(n) | most-optimal-approach-tc-on-by-aayushaga-vm79 | IntuitionImagine you’re building a string step by step, and at each step, you have to choose the next character (a,b, orc) while following two rules:
You can’t | AayushAgarwal001 | NORMAL | 2025-02-19T10:43:19.454237+00:00 | 2025-02-19T10:43:19.454237+00:00 | 47 | false |
# Intuition
Imagine you’re building a string step by step, and at each step, you have to choose the next character (`a`, `b`, or `c`) while following two rules:
1. You can’t repeat the same character twice in a row.
2. The strings must be in **alphabetical order** (like a dictionary).
The trick is that you don’t need... | 2 | 0 | ['String', 'C++'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | C++ Simple and Clean Backtracking Solution | c-simple-and-clean-backtracking-solution-6gkt | IntuitionThe functionbacktrackrecursively constructs all possible happy strings.If the current string reaches length n, it increments count.Once count reaches k | yehudisk | NORMAL | 2025-02-19T09:22:41.415388+00:00 | 2025-02-19T09:22:41.415388+00:00 | 5 | false | # Intuition
The function `backtrack` recursively constructs all possible happy strings.
If the current string reaches length n, it increments count.
Once count reaches k, the function stores the k-th happy string in res.
The loop ensures that no two consecutive characters are the same.
The function getHappyString init... | 2 | 0 | ['C++'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Begineer Friendly Backtracking Solution | Very easy intuition and approch | Easy to understand | begineer-friendly-backtracking-solution-86q8y | IntuitionThe problem requires generating "happy strings" of lengthn. A happy string is a string consisting of only 'a', 'b', and 'c' where no two adjacent chara | ParthTiwari01 | NORMAL | 2025-02-19T08:51:10.041683+00:00 | 2025-02-19T08:51:10.041683+00:00 | 38 | false |
# **Intuition**
The problem requires generating "happy strings" of length `n`. A happy string is a string consisting of only 'a', 'b', and 'c' where no two adjacent characters are the same.
Our goal is to generate all such strings in lexicographical order and return the `k`-th string.
---
# **Approach**
1. **B... | 2 | 0 | ['String', 'Backtracking', 'C++'] | 1 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | ✅ Beat 100% runtime, O(N x K) Time, O(N) Space| no recursion, solution generating next permutation | beat-100-runtime-on-x-k-time-on-space-wi-t69c | IntuitionWe need kth lexicographical happy string of length n.If we know the first string (smallest lexicographically) and a way to generate the next lexicograp | astrothames | NORMAL | 2025-02-19T08:39:56.339343+00:00 | 2025-02-20T05:11:29.332448+00:00 | 26 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We need kth lexicographical happy string of length n.
If we know the first string (smallest lexicographically) and a way to generate the next lexicographical happy string from the given string, we would simply use it k-1 times to get kth le... | 2 | 0 | ['String', 'Greedy', 'C++'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Beats 100% || Simple Backtracing Code || Easily Understandable approch | beats-100-simple-backtracing-code-easily-ogmv | IntuitionA "happy string" of lengthnconsists of charactersa,b, andcsuch that no two adjacent characters are the same. To find thek-th lexicographically smallest | 717822f143 | NORMAL | 2025-02-19T08:32:40.735644+00:00 | 2025-02-19T08:32:40.735644+00:00 | 20 | false |
**Intuition**
A "happy string" of lengthnconsists of charactersa,b, andcsuch that no two adjacent characters are the same. To find thek-th lexicographically smallest happy string, we can generate all valid strings in lexicographical order and return thek-th one.
**Approach**
Userecursive backtrackingapproach to gener... | 2 | 0 | ['Java'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Simple Math Solution -> No Backtracking O(N) Explained | simple-math-solution-no-backtracking-on-22dwa | IntuitionThe question requires formation of specific happy strings. Instead of DFS, one can focus on simple maths solution which can perform same operation in e | Nitkapur30 | NORMAL | 2025-02-19T08:10:42.777138+00:00 | 2025-02-19T08:10:42.777138+00:00 | 24 | false | # Intuition
The question requires formation of specific happy strings. Instead of DFS, one can focus on simple maths solution which can perform same operation in equal time.
Let us consider happy strings formation :
#### Length n = 1
Happy Strings : ["a", "b", "c" ]
```Number of strings starting with a = 1```
```N... | 2 | 0 | ['Math', 'C++'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Begginner's Friendly || C++ | begginners-friendly-c-by-manish_8312-ppt1 | IntuitionThe problem requires generating lexicographically ordered "happy" strings of lengthnusing the characters'a','b', and'c', where no two adjacent characte | manish_code_fun | NORMAL | 2025-02-19T07:58:10.756827+00:00 | 2025-02-19T07:58:10.756827+00:00 | 47 | false | # Intuition
The problem requires generating lexicographically ordered "happy" strings of length `n` using the characters `'a'`, `'b'`, and `'c'`, where no two adjacent characters are the same. The goal is to find the `k`-th such string.
# Approach
1. Use **backtracking** to generate all valid happy strings of le... | 2 | 0 | ['C++'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Python 🐍| Easy Explanation to Understand 💡 | python-easy-explanation-to-understand-by-odsd | IntuitionThe problem requires generating ahappy stringof lengthn, where no two adjacent characters are the same.Instead of generating all possible strings and f | nxr_deen | NORMAL | 2025-02-19T07:45:22.892465+00:00 | 2025-02-19T07:45:22.892465+00:00 | 31 | false | # Intuition
The problem requires generating a **happy string** of length `n`, where no two adjacent characters are the same.
Instead of generating all possible strings and filtering invalid ones, we can use **backtracking** to construct valid happy strings directly in lexicographical order.
This allows us to stop e... | 2 | 0 | ['String', 'Backtracking', 'Python'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Kotlin. Beats 100% (1 ms). Simple DFS | kotlin-beats-100-1-ms-simple-dfs-by-mobd-whgc | Code | mobdev778 | NORMAL | 2025-02-19T07:42:00.048647+00:00 | 2025-02-19T07:42:00.048647+00:00 | 35 | false | 
# Code
```kotlin []
class Solution {
var k = 0
fun getHappyString(n: Int, k: Int): String {
val chars = CharArray(n)
this.k = k
if (dfs(chars, 0, ' ')) return String(char... | 2 | 0 | ['Kotlin'] | 1 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | 🚀🔥C++ | Easy Solution using Backtracking | c-easy-solution-using-backtracking-by-aa-y854 | Intuition💡The problem requires generating happy strings of length n, where:To solve this, we can recursively build all valid strings while ensuring that no two | AashutoshRaut | NORMAL | 2025-02-19T07:34:36.715947+00:00 | 2025-02-19T07:34:36.715947+00:00 | 32 | false | # Intuition💡
The problem requires generating happy strings of length n, where:
A happy string consists of only 'a', 'b', and 'c'.
No two adjacent characters should be the same.
We need to return the k-th lexicographically smallest happy string.
To solve this, we can recursively build all valid strings whi... | 2 | 0 | ['C++'] | 1 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Recursive solution using Python | Beats 100% 📈📈📈 | python-solution-beats-76-of-other-soluti-7w4m | IntuitionTotal number of possible strings=3×2N−1IfK>3×2N−1return"".Approach
Create an array to store the happy strings.
There are 2 base conditions:
Length of t | dark_mortal | NORMAL | 2025-02-19T07:08:25.206434+00:00 | 2025-02-20T09:56:50.338282+00:00 | 81 | false | # Intuition
Total number of possible strings $=3\times2^{N-1}$
If $K>3\times2^{N-1}$ return `""`.
# Approach
- Create an array to store the happy strings.
- There are 2 base conditions:
- Length of the string being made $=N$.
- Length of the happy-string array $=K$.
- Get the current last character of the strin... | 2 | 0 | ['Bit Manipulation', 'Recursion', 'Python3'] | 1 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Simple Java Solution🚀|| Well Explained✅|| Beginner Friendly🔥 | simple-java-solution-well-explained-begi-w45e | IntuitionThe problem requires us to generate all happy strings of length n, sort them lexicographically, and return the k-th string. Given that n is small (≤ 10 | ghumeabhi04 | NORMAL | 2025-02-19T06:54:24.592386+00:00 | 2025-02-19T06:54:24.592386+00:00 | 102 | false | # Intuition
The problem requires us to generate all happy strings of length n, sort them lexicographically, and return the k-th string. Given that n is small (≤ 10), a backtracking approach is efficient for generating all valid strings.
---
# Approach
1. Backtracking to generate happy strings:
- Use a helper fu... | 2 | 0 | ['String', 'Backtracking', 'Java'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | BEATS 99.09% SOLUTIONS | JAVA | Explained With Comments !!! | beats-9909-solutions-java-explained-with-dj12 | Code | Siddharth_Bahuguna | NORMAL | 2025-02-19T06:25:43.902531+00:00 | 2025-02-19T06:25:43.902531+00:00 | 91 | false |
# Code
```java []
class Solution {
String res;
int count;
public String getHappyString(int n, int k) {
count=0;
res="";
backtrack(n,k,new StringBuilder(""));
return res;
}
public boolean backtrack(int n,int k,StringBuilder cur){
if(cur.length()==n){ //if str... | 2 | 0 | ['Java'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Backtracking with Lexicographic Ordering | backtracking-with-lexicographic-ordering-mhab | IntuitionA "happy string" is a string of length n formed using the characters {'a', 'b', 'c'}, where no two adjacent characters are the same. Since we need the | poonammalik9817 | NORMAL | 2025-02-19T06:17:03.712022+00:00 | 2025-02-19T06:17:03.712022+00:00 | 7 | false | # Intuition
A "happy string" is a string of length n formed using the characters {'a', 'b', 'c'}, where no two adjacent characters are the same. Since we need the k-th lexicographical happy string, we can use backtracking to generate them in order and return the k-th result.
# Approach
1. Use backtracking to generate ... | 2 | 0 | ['String', 'Backtracking', 'C++'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Simple Solution || More like a brute | simple-solution-more-like-a-brute-by-kan-rp8v | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Kanishq_24je3 | NORMAL | 2025-02-19T06:07:51.437810+00:00 | 2025-02-19T06:07:51.437810+00:00 | 34 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 2 | 0 | ['Backtracking', 'C++'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | 🔥🔥 Go Solution || 0ms Runtime || beats 100% | go-solution-0ms-runtime-beats-100-by-sha-g7v3 | 🙏🏼 If you find this helpful please don't forget to upvote👍 🙏🏼IntuitionFirst we will check for the count of all possible happy strings. To get that we will use t | ShaliniYadav09 | NORMAL | 2025-02-19T05:08:03.768242+00:00 | 2025-02-20T11:34:41.362651+00:00 | 86 | false | ## 🙏🏼 If you find this helpful please don't forget to upvote👍 🙏🏼
# Intuition
First we will check for the count of all possible happy strings. To get that we will use the formula (3*(2^(n-1))) as for the first place the possible characters are 3 and for the rest of the poisitions are 2. If the total possible string... | 2 | 0 | ['Go'] | 1 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Simple Backtracking Solution✅✅ | simple-backtracking-solution-by-karthike-t622 | IntuitionThe problem requires generating lexicographically ordered "happy strings" of length 𝑛, where no two adjacent characters are the same. We need to find t | karthikeyan__05 | NORMAL | 2025-02-19T04:53:59.526752+00:00 | 2025-02-21T07:13:58.477271+00:00 | 16 | false | 
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem requires generating lexicographically ordered "happy strings" of length 𝑛, where no two a... | 2 | 0 | ['Backtracking', 'Java'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | ✅✅Beginner Friendly Easy solution || c++ python3 java || TC :O(n) SC :O(1) || 🔥Beats 100%🔥 | beginner-friendly-easy-solution-c-python-62iw | IntuitionApproachComplexity
Time complexity: O(n)
Space complexity: O(1)
Code | HrsilmalanI | NORMAL | 2025-02-19T04:50:28.829126+00:00 | 2025-02-19T04:55:37.281448+00:00 | 23 | false | 
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time comp... | 2 | 1 | ['String', 'Binary Search', 'Combinatorics', 'C++', 'Java', 'Python3'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Java Faster than 100% | Greedy approach | java-faster-than-100-greedy-approach-by-3kxsm | IntuitionEliminate unwanted string sets at each index.
If you observe starting with each letter you can make at most 2^n-1 combinations because at each index yo | Ayuj_Gupta | NORMAL | 2025-02-19T04:36:49.559899+00:00 | 2025-02-19T04:36:49.559899+00:00 | 38 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Eliminate unwanted string sets at each index.
- If you observe starting with each letter you can make at most 2^n-1 combinations because at each index you can choose from 2 options only.
- Ex if n=4 then there are atmax 8 combinations start... | 2 | 0 | ['Greedy', 'Java'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Easy Java Solution (Backtracking) | easy-java-solution-backtracking-by-joesh-2mdi | Intuition
A happy string is a string where no two adjacent characters are the same, and it consists of only the letters 'a', 'b', and 'c'. The task is to find t | joesharon | NORMAL | 2025-02-19T04:36:11.005939+00:00 | 2025-02-19T04:36:11.005939+00:00 | 82 | false | # Intuition
- A happy string is a string where no two adjacent characters are the same, and it consists of only the letters 'a', 'b', and 'c'. The task is to find the k-th lexicographically smallest happy string of length n.
- The natural approach is to generate all possible happy strings recursively, ensuring that ad... | 2 | 0 | ['String', 'Backtracking', 'Recursion', 'Java'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Beginner friendly || Beats 100% || Easy to Understand 🔥 | beginner-friendly-beats-100-easy-to-unde-u6af | IntuitionThe problem requires generating lexicographically ordered happy strings of length n using charactersa,b, andc, where no two adjacent characters are the | omkarsalunkhe3597 | NORMAL | 2025-02-19T04:26:40.832000+00:00 | 2025-02-19T04:26:40.832000+00:00 | 41 | false | # Intuition
The problem requires generating lexicographically ordered happy strings of length n using characters `a`, `b`, and `c`, where no two adjacent characters are the same. We need to find the `k-th` such string.
# Approach
We use a recursive backtracking approach to generate happy strings of length n.
1. Start w... | 2 | 0 | ['String', 'Backtracking', 'C++'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | My kotlin solution with time O(n) and space O(n) | my-kotlin-solution-with-time-on-and-spac-0rkw | One idea is to generate the happy strings in order up to the kth one and return it. However, a better way is to use the knowledge of permutations and decide the | hj-core | NORMAL | 2025-02-19T04:25:31.108638+00:00 | 2025-02-19T14:15:11.433034+00:00 | 73 | false | One idea is to generate the happy strings in order up to the kth one and return it. However, a better way is to use the knowledge of permutations and decide the characters one by one. Here are some suggestions to understand the idea:
1. Understand that the maximum k is 3 * 2^(n-1).
2. Understand how to choose the first... | 2 | 0 | ['Go', 'Kotlin'] | 2 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | Easy code in java, must try | easy-code-in-java-must-try-by-notaditya0-932e | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | NotAditya09 | NORMAL | 2025-02-19T04:09:25.356361+00:00 | 2025-02-19T04:09:25.356361+00:00 | 97 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 2 | 0 | ['Java'] | 0 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | A Backtracking Approach | 100% beats in time complexity | C++ | a-backtracking-approach-100-beats-in-tim-quqb | Intuition
A happy string is defined as a string consisting solely of the characters 'a', 'b', and 'c', with the additional constraint that no two adjacent chara | Mohamed_Hamdan_A | NORMAL | 2025-02-19T03:50:57.801158+00:00 | 2025-02-19T03:50:57.801158+00:00 | 13 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
- A happy string is defined as a string consisting solely of the characters 'a', 'b', and 'c', with the additional constraint that no two adjacent characters are the same. Notably, the total number of happy strings of length n is exactly
... | 2 | 0 | ['Backtracking', 'Depth-First Search', 'C++'] | 1 |
the-k-th-lexicographical-string-of-all-happy-strings-of-length-n | just an easy understandable solution in java using recursion | just-a-easy-understandable-solution-in-j-xzie | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | yasl1 | NORMAL | 2025-02-19T03:41:10.252782+00:00 | 2025-02-19T03:41:34.439947+00:00 | 79 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 2 | 0 | ['String', 'Backtracking', 'Recursion', 'Java'] | 0 |
longest-substring-without-repeating-characters | ✅3 Method's || C++ || JAVA || PYTHON || Beginner Friendly🔥🔥🔥 | 3-methods-c-java-python-beginner-friendl-ck47 | 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 witho | rahulvarma5297 | NORMAL | 2023-06-17T18:59:44.076656+00:00 | 2023-06-17T18:59:44.076673+00:00 | 526,077 | false | # 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... | 2,115 | 2 | ['Hash Table', 'String', 'C++', 'Java', 'Python3'] | 76 |
longest-substring-without-repeating-characters | 11-line simple Java solution, O(n) with explanation | 11-line-simple-java-solution-on-with-exp-ar3s | the basic idea is, keep a hashmap which stores the characters in string as keys and their positions as values, and keep two pointers which define the max substr | cbmbbz | NORMAL | 2015-02-01T02:05:51+00:00 | 2018-10-25T02:01:33.610243+00:00 | 407,935 | false | the basic idea is, keep a hashmap which stores the characters in string as keys and their positions as values, and keep two pointers which define the max substring. move the right pointer to scan through the string , and meanwhile update the hashmap. If the character is already in the hashmap, then move the left pointe... | 1,914 | 25 | [] | 197 |
longest-substring-without-repeating-characters | 【Video】3 ways to solve this question - sliding window, set, hashing and the last position | video-3-ways-to-solve-this-question-slid-uupi | Solution Video⭐️⭐️ Don't forget to subscribe to my channel! ⭐️⭐️■ Subscribe URL
http://www.youtube.com/channel/UC9RMNwYTL3SXCP6ShLWVFww?sub_confirmation=1Subscr | niits | NORMAL | 2024-05-04T13:59:41.350430+00:00 | 2025-03-29T09:14:42.904527+00:00 | 143,475 | false | # Solution Video
https://youtu.be/n4zCTMh03_M
### ⭐️⭐️ Don't forget to subscribe to my channel! ⭐️⭐️
**■ Subscribe URL**
http://www.youtube.com/channel/UC9RMNwYTL3SXCP6ShLWVFww?sub_confirmation=1
Subscribers: 3,982
Thank you for your support!
---
# Approach
We have two conditions to solve this question. The longe... | 1,206 | 0 | ['Hash Table', 'Two Pointers', 'String', 'Sliding Window', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 15 |
longest-substring-without-repeating-characters | C++ code in 9 lines. | c-code-in-9-lines-by-lightmark-le6b | int lengthOfLongestSubstring(string s) {\n vector<int> dict(256, -1);\n int maxLen = 0, start = -1;\n for (int i = 0; i != s.le | lightmark | NORMAL | 2015-09-19T06:36:51+00:00 | 2018-10-23T02:36:21.517297+00:00 | 212,247 | false | int lengthOfLongestSubstring(string s) {\n vector<int> dict(256, -1);\n int maxLen = 0, start = -1;\n for (int i = 0; i != s.length(); i++) {\n if (dict[s[i]] > start)\n start = dict[s[i]];\n dict[s[i]] = i;\n maxLen = ... | 1,122 | 12 | ['C++'] | 164 |
longest-substring-without-repeating-characters | [Java/C++] A reall Detailed Explanation | javac-a-reall-detailed-explanation-by-hi-c3q2 | So, the prerequisit of this problem is Sliding Window, if you know then it\'s a plus point. But, if you don\'t know don\'t worry I\'ll try to teach you.\n\nLet\ | hi-malik | NORMAL | 2022-06-10T05:34:17.651699+00:00 | 2022-06-10T05:50:45.746828+00:00 | 125,070 | false | So, the prerequisit of this problem is **Sliding Window**, if you know then it\'s a plus point. But, if you don\'t know don\'t worry I\'ll try to teach you.\n\nLet\'s understand first of all what the problem is saying!!\n```\nGiven a string s, find the length of the longest substring without repeating characters.\n```\... | 1,042 | 3 | ['C', 'Java'] | 45 |
longest-substring-without-repeating-characters | Share my Java solution using HashSet | share-my-java-solution-using-hashset-by-6sr65 | The idea is use a hash set to track the longest substring without repeating characters so far, use a fast pointer j to see if character j is in the hash set or | jeantimex | NORMAL | 2015-09-27T00:36:56+00:00 | 2018-10-26T18:21:51.646803+00:00 | 122,706 | false | The idea is use a hash set to track the longest substring without repeating characters so far, use a fast pointer j to see if character j is in the hash set or not, if not, great, add it to the hash set, move j forward and update the max length, otherwise, delete from the head by using a slow pointer i until we can put... | 948 | 7 | ['Java'] | 79 |
longest-substring-without-repeating-characters | Used HashSet in JAVA ✅ || Explained Approach | used-hashset-in-java-explained-approach-ifhi6 | Intuition\n Describe your first thoughts on how to solve this problem. \nif you know sliding window...then it can be intuitive. But if you don\'t know ...no wor | rachit615 | NORMAL | 2023-02-07T19:29:17.663863+00:00 | 2023-02-07T19:29:17.663906+00:00 | 158,706 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nif you know sliding window...then it can be intuitive. But if you don\'t know ...no worry i will teach you...\nRefer below approach points.....\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Use sliding window wi... | 933 | 3 | ['Hash Table', 'Sliding Window', 'Python', 'C++', 'Java'] | 37 |
longest-substring-without-repeating-characters | [Python3]: sliding window O(N) with explanation | python3-sliding-window-on-with-explanati-zont | 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 th | zhanweiting | NORMAL | 2019-07-31T07:54:07.671471+00:00 | 2019-12-19T07:41:39.958652+00:00 | 134,737 | false | **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... | 876 | 3 | ['Python', 'Python3'] | 50 |
longest-substring-without-repeating-characters | A Python solution - 85ms - O(n) | a-python-solution-85ms-on-by-google-1yh4 | class Solution:\n # @return an integer\n def lengthOfLongestSubstring(self, s):\n start = maxLength = 0\n usedChar = {}\n | google | NORMAL | 2015-04-09T00:16:40+00:00 | 2018-10-26T15:12:55.411653+00:00 | 184,061 | false | class Solution:\n # @return an integer\n def lengthOfLongestSubstring(self, s):\n start = maxLength = 0\n usedChar = {}\n \n for i in range(len(s)):\n if s[i] in usedChar and start <= usedChar[s[i]]:\n start = usedChar[s[i]]... | 642 | 8 | ['Python'] | 89 |
longest-substring-without-repeating-characters | CPP Solution for beginners | O(n) time | Longest Substring without repeating characters | cpp-solution-for-beginners-on-time-longe-vyds | A solution for beginners, which is straightforward, easy to understand, without too many complications and room to optimize once you understand the basic premis | sidthakur1 | NORMAL | 2019-09-06T22:39:00.036043+00:00 | 2019-09-09T03:28:55.479232+00:00 | 42,440 | false | A solution for beginners, which is straightforward, easy to understand, without too many complications and room to optimize once you understand the basic premise of the question. Hope this helps!\n\nTime Complexity: O(n)\nSpace Complexity: O(min of a,b) for the unordered set. a, is the upper bound of the space complexi... | 519 | 3 | ['Sliding Window', 'C++'] | 43 |
longest-substring-without-repeating-characters | Simple Explanation | Concise | Thinking Process & Example | simple-explanation-concise-thinking-proc-n2zl | Lets start with the following example: \n\nAssume you had no repeating characters (In below example, just look at first three characters)\n\nWe take two pointer | ivankatrump | NORMAL | 2020-07-18T23:38:26.530759+00:00 | 2020-10-11T23:46:53.948437+00:00 | 27,114 | false | 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 ... | 388 | 13 | ['Python', 'Python3'] | 13 |
longest-substring-without-repeating-characters | ✅ best C++ fast solution | best-c-fast-solution-by-coding_menance-3hao | C++ Code\nC++ []\nclass Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n if(s.length()==0)return 0; //if string of length zero comes | coding_menance | NORMAL | 2023-03-10T08:53:11.155472+00:00 | 2023-03-10T08:53:18.032984+00:00 | 65,381 | false | # C++ Code\n``` C++ []\nclass Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n if(s.length()==0)return 0; //if string of length zero comes simply return 0\n unordered_map<char,int> m; //create map to store frequency,(get to know all unique characters\n int i=0,j=0,ans=INT_MIN... | 271 | 1 | ['C++'] | 7 |
longest-substring-without-repeating-characters | SLIDING WINDOW || O(n) || Faster than 90% and Memory usage less than 100% | sliding-window-on-faster-than-90-and-mem-haid | \nclass Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n \n //SLIDING WINDOW - TIME COMPLEXITY O(2n)\n // | kush980 | NORMAL | 2021-01-13T14:35:43.589865+00:00 | 2021-01-14T08:41:51.107291+00:00 | 29,536 | false | ```\nclass Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n \n //SLIDING WINDOW - TIME COMPLEXITY O(2n)\n // SPACE COMPLEXITY O(m) //size of array\n \n int store[256]={0}; //array to store the occurences of all the characters\n int l=0; ... | 270 | 2 | ['C', 'Sliding Window', 'C++'] | 10 |
longest-substring-without-repeating-characters | JS | 98% | Sliding window | With exlanation | js-98-sliding-window-with-exlanation-by-4ymyu | \n\nWindow Sliding Technique is a computational technique which aims to reduce the use of nested loop and replace it with a single loop, thereby reducing the ti | Karina_Olenina | NORMAL | 2022-10-12T11:55:48.311868+00:00 | 2022-10-18T07:39:40.543988+00:00 | 49,554 | false | \n\n**Window Sliding Technique** is a computational technique which aims to reduce the use of nested loop and replace it with a single loop, thereby reducing the time complexity.\nThe Sliding window technique c... | 247 | 0 | ['Hash Table', 'Sliding Window', 'JavaScript'] | 28 |
longest-substring-without-repeating-characters | Shortest O(n) DP solution with explanations | shortest-on-dp-solution-with-explanation-20o5 | /**\n * Solution (DP, O(n)):\n * \n * Assume L[i] = s[m...i], denotes the longest substring without repeating\n * characters that ends up at s[i | dragonmigo | NORMAL | 2014-10-15T19:04:06+00:00 | 2018-10-21T19:30:09.865979+00:00 | 72,105 | false | /**\n * Solution (DP, O(n)):\n * \n * Assume L[i] = s[m...i], denotes the longest substring without repeating\n * characters that ends up at s[i], and we keep a hashmap for every\n * characters between m ... i, while storing <character, index> in the\n * hashmap.\n * We know that each ch... | 204 | 16 | [] | 28 |
longest-substring-without-repeating-characters | 9 line JavaScript solution | 9-line-javascript-solution-by-linfongi-jjkl | function lengthOfLongestSubstring(s) {\n const map = {};\n var left = 0;\n \n return s.split('').reduce((max, v, i) => {\n | linfongi | NORMAL | 2015-08-16T02:03:54+00:00 | 2018-09-01T11:10:40.901014+00:00 | 33,939 | false | function lengthOfLongestSubstring(s) {\n const map = {};\n var left = 0;\n \n return s.split('').reduce((max, v, i) => {\n left = map[v] >= left ? map[v] + 1 : left;\n map[v] = i;\n return Math.max(max, i - left + 1);\n }, 0);\n } | 144 | 4 | ['JavaScript'] | 20 |
longest-substring-without-repeating-characters | Visual Explanation | Sliding Window JAVA | visual-explanation-sliding-window-java-b-k6qn | Logic:\nThis difficulty in this question is finding out where to pick our next substring once we\'ve spotted a duplicate character. Using two pointers and a sli | ciote | NORMAL | 2022-06-10T00:54:05.592016+00:00 | 2022-10-22T23:42:42.487283+00:00 | 13,596 | false | ### Logic:\nThis difficulty in this question is finding out where to pick our next substring once we\'ve spotted a duplicate character. Using two pointers and a sliding window, we can quite easily choose what substring we want to look at. In fact, finding the longest substring without repeating characters becomes even ... | 123 | 0 | ['Sliding Window', 'Java'] | 12 |
longest-substring-without-repeating-characters | ✅Short||C++||Expained Solution|| 11 line code | shortcexpained-solution-11-line-code-by-7s5u6 | Intuition\n Describe your first thoughts on how to solve this problem. \nWe have to find the length of longest substring which does not contain any repeating ch | divyanshu851_8 | NORMAL | 2022-11-11T21:43:13.965108+00:00 | 2022-11-19T17:55:24.609495+00:00 | 18,663 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe have to find the length of longest substring which does not contain any repeating characters\n\nThe first thing which should come in our mind is to traverse in the string and store the frequence of each character in a map type of "map<... | 117 | 0 | ['Two Pointers', 'String', 'Sliding Window', 'C++', 'Java'] | 10 |
longest-substring-without-repeating-characters | ✅ best JAVA fast solution | best-java-fast-solution-by-coding_menanc-airr | JAVA Code\nJAVA []\nclass Solution {\n public int lengthOfLongestSubstring(String s) {\n Set<Character>set=new HashSet<>();\n int maxLength=0;\ | coding_menance | NORMAL | 2023-03-10T05:18:42.132342+00:00 | 2023-03-10T05:18:42.132377+00:00 | 25,799 | false | # JAVA Code\n``` JAVA []\nclass Solution {\n public int lengthOfLongestSubstring(String s) {\n Set<Character>set=new HashSet<>();\n int maxLength=0;\n int left=0;\n for(int right=0;right<s.length();right++){\n \n if(!set.contains(s.charAt(right))){\n se... | 103 | 0 | ['Java'] | 4 |
longest-substring-without-repeating-characters | Python solution with comments. | python-solution-with-comments-by-oldcodi-znnd | \n def lengthOfLongestSubstring(self, s):\n dic, res, start, = {}, 0, 0\n for i, ch in enumerate(s):\n if ch in dic:\n | oldcodingfarmer | NORMAL | 2015-08-12T13:52:34+00:00 | 2020-09-14T11:14:16.730549+00:00 | 40,658 | false | \n def lengthOfLongestSubstring(self, s):\n dic, res, start, = {}, 0, 0\n for i, ch in enumerate(s):\n if ch in dic:\n res = max(res, i-start) # update the res\n start = max(start, dic[ch]+1) # here should be careful, like "abba"\n dic[ch] = i\n ... | 94 | 4 | ['Python'] | 16 |
longest-substring-without-repeating-characters | ✅ [Python/C++/Java/Rust] 0 ms, position difference (with detailed comments) | pythoncjavarust-0-ms-position-difference-sxit | \u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.\n*\nThis solution employs storage of positions and calculation of their differences for repeated characters. Ti | stanislav-iablokov | NORMAL | 2022-10-24T13:46:35.027892+00:00 | 2022-10-24T13:48:06.683681+00:00 | 15,640 | false | **\u2705 IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n****\nThis solution employs storage of positions and calculation of their differences for repeated characters. Time complexity is linear: **O(N)**. Space complexity is constant: **O(1)**. \n\n| Language | [**Python**](https://leetcode.com/submissions/detail/82919617... | 87 | 0 | ['C', 'Python', 'Java', 'Rust'] | 8 |
longest-substring-without-repeating-characters | C++ Solution using Set | c-solution-using-set-by-sheldonbang-h4fd | ```\n int lengthOfLongestSubstring(string s) {\n int n=s.length();\n if(n==0)\n return 0;\n set st;\n int maxsize=0;\n | sheldonbang | NORMAL | 2020-04-13T04:05:07.043365+00:00 | 2020-04-13T04:09:26.383439+00:00 | 12,729 | false | ```\n int lengthOfLongestSubstring(string s) {\n int n=s.length();\n if(n==0)\n return 0;\n set<char> st;\n int maxsize=0;\n int i=0,j=0;\n while(j<n)\n {\n if(st.count(s[j])==0)\n {\n st.insert(s[j]);\n m... | 85 | 3 | ['C', 'Ordered Set', 'C++'] | 12 |
longest-substring-without-repeating-characters | C++ | All approaches: brute force, Sliding Window | 12ms | map | Solution for Longest Substring | c-all-approaches-brute-force-sliding-win-nnmk | Dear All,\n\nI solved this issue with different approaches and happy to share with you. Probably looking to all of them and comparing you will understand which | YevRad | NORMAL | 2021-03-18T14:40:52.986320+00:00 | 2021-03-29T14:32:52.126099+00:00 | 10,892 | false | Dear All,\n\nI solved this issue with different approaches and happy to share with you. Probably looking to all of them and comparing you will understand which one is better and why. All solutions containes comments for your better understanding of algorithm. Hope you will enjoy =)\n\nPlease find below my last and best... | 83 | 3 | ['C', 'Sliding Window', 'Iterator', 'C++'] | 5 |
longest-substring-without-repeating-characters | JavaScript Clean Heavily Commented Solution | javascript-clean-heavily-commented-solut-mshw | Time Complexity = O(N)\nSpace Complexity = O(N)\njavascript\nvar lengthOfLongestSubstring = function(s) {\n // keeps track of the most recent index of each l | control_the_narrative | NORMAL | 2020-07-12T04:05:25.403290+00:00 | 2020-07-12T04:07:03.555514+00:00 | 14,979 | false | Time Complexity = `O(N)`\nSpace Complexity = `O(N)`\n```javascript\nvar lengthOfLongestSubstring = function(s) {\n // keeps track of the most recent index of each letter.\n const seen = new Map();\n // keeps track of the starting index of the current substring.\n let start = 0;\n // keeps track of the ma... | 76 | 0 | ['JavaScript'] | 11 |
longest-substring-without-repeating-characters | O(n) | Beats 100 % | Sliding Window | Java | C++ | Python | Go | Rust | JavaScript | on-beats-100-sliding-window-java-c-pytho-8kf6 | Intuition\n\nThe problem asks us to find the length of the longest substring without repeating characters. It might sound a bit technical at first, but we can b | kartikdevsharma_ | NORMAL | 2024-09-21T16:06:17.735940+00:00 | 2024-09-22T16:35:45.780654+00:00 | 12,090 | false | ## Intuition\n\nThe problem asks us to find the length of the **longest substring without repeating characters**. It might sound a bit technical at first, but we can break it down: \nImagine you\u2019re given a string, like "abcabcbb". What we\u2019re really being asked is, "What\u2019s the longest continuous chunk of ... | 67 | 0 | ['Hash Table', 'Sliding Window', 'C++', 'Java', 'Go', 'Python3', 'Rust', 'JavaScript'] | 8 |
longest-substring-without-repeating-characters | Python easy solution with comment 90% O(n) speed & 98% space | python-easy-solution-with-comment-90-on-qdnm4 | \nclass Solution(object):\n def lengthOfLongestSubstring(self, s):\n seen = \'\'\n mx = 0\n\t\t#1. for each character in s\n for c in s: | kevinko1788 | NORMAL | 2019-09-24T16:12:04.712395+00:00 | 2021-09-12T04:22:11.694672+00:00 | 9,175 | false | ```\nclass Solution(object):\n def lengthOfLongestSubstring(self, s):\n seen = \'\'\n mx = 0\n\t\t#1. for each character in s\n for c in s:\n\t\t\t#2. check if c is seen\n if c not in seen:\n\t\t\t#3. if not seen, add to seen list \n seen+=c\n #4 if seen, sli... | 67 | 3 | ['Python'] | 10 |
longest-substring-without-repeating-characters | ✅ [Accepted] Solution for Swift | accepted-solution-for-swift-by-asahiocea-jsiu | \nDisclaimer: By using any content from this post or thread, you release the author(s) from all liability and warranty of any kind. You are free to use the cont | AsahiOcean | NORMAL | 2021-03-30T20:31:01.920651+00:00 | 2023-12-29T22:06:49.585162+00:00 | 9,989 | false | <blockquote>\n<b>Disclaimer:</b> By using any content from this post or thread, you release the author(s) from all liability and warranty of any kind. You are free to use the content freely and as you see fit. Any suggestions for improvement are welcome and greatly appreciated! Happy coding!\n</blockquote>\n\n```swift\... | 60 | 3 | ['Swift'] | 4 |
longest-substring-without-repeating-characters | Java | TC: O(N) | SC: O(1) | Sliding Window using HashMap & Two Pointers | java-tc-on-sc-o1-sliding-window-using-ha-k4qb | java\n/**\n * Use HashMap to keep char and its index map. When we find a repeating char\n * update the start point.\n *\n * Time Complexity: O(N)\n *\n * Space | NarutoBaryonMode | NORMAL | 2021-10-03T10:42:07.313990+00:00 | 2021-10-07T07:57:27.034560+00:00 | 7,059 | false | ```java\n/**\n * Use HashMap to keep char and its index map. When we find a repeating char\n * update the start point.\n *\n * Time Complexity: O(N)\n *\n * Space Complexity: O(min(M,N)) = O(1) since there are 26 alphabets.\n *\n * N = Length of input string. M = Size of the character set\n */\nclass Solution {\n pu... | 58 | 1 | ['Two Pointers', 'String', 'Sliding Window', 'Java'] | 3 |
longest-substring-without-repeating-characters | 4ms C code in 12 lines | 4ms-c-code-in-12-lines-by-tongxing-kcrx | int lengthOfLongestSubstring(char* s)\n {\n \tint len=0;\n char *end=s,*temp;\n \tchar* addressTable[128]={NULL};\n \twhile(*end){\n \t\tt | tongxing | NORMAL | 2015-07-30T17:27:55+00:00 | 2018-10-24T01:27:41.214611+00:00 | 17,328 | false | int lengthOfLongestSubstring(char* s)\n {\n \tint len=0;\n char *end=s,*temp;\n \tchar* addressTable[128]={NULL};\n \twhile(*end){\n \t\ttemp = addressTable[*end];\n \t\taddressTable[*end]=end;\n \t\tif(temp>=s){\n \t\tlen=end-s>len?end-s:len;\n \t\ts = temp+1;\n \t\t}end++;\n ... | 55 | 2 | [] | 15 |
longest-substring-without-repeating-characters | Fast(>98%) and simple code in Javascript solution | fast98-and-simple-code-in-javascript-sol-jrw7 | javascript\nvar lengthOfLongestSubstring = function(s) {\n var sLen = s.length,\n maxLen = 0,\n maxStr = '',\n tmpStr,\n posIndex,\n i;\n\n for | arrowing | NORMAL | 2017-06-23T07:47:29.797000+00:00 | 2017-06-23T07:47:29.797000+00:00 | 10,845 | false | ```javascript\nvar lengthOfLongestSubstring = function(s) {\n var sLen = s.length,\n maxLen = 0,\n maxStr = '',\n tmpStr,\n posIndex,\n i;\n\n for( i = 0 ; i < sLen; i++ ){\n\n tmpStr = s[i];\n posIndex = maxStr.indexOf(tmpStr);\n\n if(posIndex > -1){\n maxStr = maxStr.substring(posIndex ... | 53 | 1 | ['JavaScript'] | 9 |
longest-substring-without-repeating-characters | Java | 2 approaches | using string functions | Hashset | java-2-approaches-using-string-functions-0zf5 | \nPLEASE UPVOTE IF IT HELPS YOU :)\n\n\nApproach 1: Using basic string functions\nclass Solution {\n public int lengthOfLongestSubstring(String s) {\n | tarushi0503 | NORMAL | 2022-01-31T13:35:20.346054+00:00 | 2022-01-31T14:30:28.631409+00:00 | 3,538 | false | ```\nPLEASE UPVOTE IF IT HELPS YOU :)\n\n\nApproach 1: Using basic string functions\nclass Solution {\n public int lengthOfLongestSubstring(String s) {\n if(s.length()==0)\n return 0;\n char ch=s.charAt(0);\n String ans="";\n ans=ans+ch;\n int max=1;\n for(int i=1... | 47 | 1 | ['Sliding Window', 'Java'] | 5 |
longest-substring-without-repeating-characters | C++ Sliding Window & Hash Map Easy Solution | c-sliding-window-hash-map-easy-solution-84oqp | \nclass Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n \n unordered_map<char,int> index;\n int start=0,res=0;\n | hitengoyal18 | NORMAL | 2021-04-26T06:30:40.639634+00:00 | 2021-04-26T06:30:40.639665+00:00 | 6,376 | false | ```\nclass Solution {\npublic:\n int lengthOfLongestSubstring(string s) {\n \n unordered_map<char,int> index;\n int start=0,res=0;\n for(int i=0;i<s.length();i++){\n \n if (index.find(s[i]) != index.end() && index[s[i]] >= start)\n start = index[s[i]]... | 47 | 2 | ['C', 'Sliding Window', 'C++'] | 2 |
longest-substring-without-repeating-characters | Well-commented JavaScript Sliding Window solution with Set - O(n) time O(n) space | well-commented-javascript-sliding-window-8zwa | right and left are pointers in the string -- for the maxLength = Math.max.... line we could also do ...Math.max(maxLength, right - left + 1) but set.size could | albertchanged | NORMAL | 2020-11-07T20:51:02.325185+00:00 | 2020-11-07T21:14:08.823343+00:00 | 2,694 | false | ```right``` and ```left``` are pointers in the string -- for the ```maxLength = Math.max....``` line we could also do ```...Math.max(maxLength, right - left + 1)``` but ```set.size``` could make more sense for some people.\n\nExplanation is under the code.\n\n```\nvar lengthOfLongestSubstring = function(s) {\n if (!s.... | 43 | 0 | ['Sliding Window', 'JavaScript'] | 3 |
longest-substring-without-repeating-characters | JavaScript Sliding Window | javascript-sliding-window-by-daleighan-7lrj | \nfunction lengthOfLongestSubstring(s) {\n let seen = new Set();\n let longest = 0;\n let l = 0;\n for (let r = 0; r < s.length; r++) {\n while (seen.has | daleighan | NORMAL | 2020-01-10T03:47:16.267601+00:00 | 2020-01-10T03:47:16.267635+00:00 | 7,027 | false | ```\nfunction lengthOfLongestSubstring(s) {\n let seen = new Set();\n let longest = 0;\n let l = 0;\n for (let r = 0; r < s.length; r++) {\n while (seen.has(s[r])) {\n seen.delete(s[l]);\n l++;\n }\n seen.add(s[r]);\n longest = Math.max(longest, r - l + 1);\n }\n return longest;\n};\n``` | 41 | 0 | ['Sliding Window', 'JavaScript'] | 5 |
longest-substring-without-repeating-characters | My O(n) Solution | my-on-solution-by-heiyanbin-m5p0 | if only use DP, it's an O(n*n) solution, adding a map to get O(n).\n \n class Solution {\n public:\n int lengthOfLongestSubstring(string | heiyanbin | NORMAL | 2014-06-12T11:02:24+00:00 | 2014-06-12T11:02:24+00:00 | 24,095 | false | if only use DP, it's an O(n*n) solution, adding a map to get O(n).\n \n class Solution {\n public:\n int lengthOfLongestSubstring(string s) {\n if(s.size()<2) return s.size();\n int d=1, maxLen=1;\n unordered_map<char,int> map;\n map[s[... | 40 | 3 | [] | 12 |
longest-substring-without-repeating-characters | Simple Javascript Code | simple-javascript-code-by-nilath-a84b | Currently, migrating my c++ code to Javascript code.\n\n\n var lengthOfLongestSubstring = function(s) {\n var start = 0, maxLen = 0;\n var map = ne | nilath | NORMAL | 2016-12-22T16:07:48.236000+00:00 | 2016-12-22T16:07:48.236000+00:00 | 12,424 | false | Currently, migrating my c++ code to Javascript code.\n\n\n var lengthOfLongestSubstring = function(s) {\n var start = 0, maxLen = 0;\n var map = new Map();\n \n for(var i = 0; i < s.length; i++) {\n var ch = s[i];\n \n if(map.get(ch) >= start) start = map.get(ch) + 1;\n ... | 38 | 2 | [] | 8 |
longest-substring-without-repeating-characters | 8 Lines of Python code , TC: O(N) =>The easiest way anyone can understand, with 97% TC and 99% SC | 8-lines-of-python-code-tc-on-the-easiest-wo6e | \nresult =""\nmax_length = 0\nfor i in s:\n\tif i in result:\n\t\tresult = result[result.index(i)+1:]\n\t\t"""if abcdas is the string, here after abcd the lengt | sudharshan1706 | NORMAL | 2021-09-06T15:03:55.302101+00:00 | 2022-08-10T04:33:20.765587+00:00 | 2,456 | false | ```\nresult =""\nmax_length = 0\nfor i in s:\n\tif i in result:\n\t\tresult = result[result.index(i)+1:]\n\t\t"""if abcdas is the string, here after abcd the length would be 4 and result will be replaced as bcda"""\n\tresult += i\n\tmax_length = max(max_length, len(result))\nreturn (max_length)\n```\n\n\nif you underst... | 35 | 1 | ['Python'] | 6 |
longest-substring-without-repeating-characters | [Python] O(n) sliding window, explained | python-on-sliding-window-explained-by-db-evto | This is classical problem for sliding window. Let us keep window with elements [beg: end), where first element is included and last one is not. For example [0, | dbabichev | NORMAL | 2021-01-07T08:15:30.320934+00:00 | 2021-01-07T08:15:30.320979+00:00 | 1,783 | false | This is classical problem for sliding window. Let us keep window with elements `[beg: end)`, where first element is included and last one is not. For example `[0, 0)` is empty window, and `[2, 4)` is window with `2` elements: `2` and `3`.\nLet us discuss our algorithm now:\n1. `window` is set of symbols in our window, ... | 35 | 0 | ['Two Pointers', 'Sliding Window'] | 7 |
longest-substring-without-repeating-characters | My easy solution in JAVA (O(N)) . | my-easy-solution-in-java-on-by-ink213-xxij | public class Solution {\n public int lengthOfLongestSubstring(String s) {\n int[] mOccur = new int[256];\n int maxL = 0;\n | ink213 | NORMAL | 2015-08-21T09:09:16+00:00 | 2018-08-17T17:01:56.512081+00:00 | 13,733 | false | public class Solution {\n public int lengthOfLongestSubstring(String s) {\n int[] mOccur = new int[256];\n int maxL = 0;\n for(int i = 0, j = 0; i < s.length(); ++i){\n char ch = s.charAt(i);\n ++mOccur[ch];\n while(mOccur[ch] > 1)... | 34 | 2 | ['Hash Table', 'Java'] | 4 |
longest-substring-without-repeating-characters | 2 Straightforward C# Solutions w/ explanation + Sliding Window | 2-straightforward-c-solutions-w-explanat-mbj1 | Approach 1: Sliding Window\n\nImplementation\n\npublic int LengthOfLongestSubstring(string s) {\n\tvar letters = new Dictionary<char, int>(); // key:letter, val | minaohhh | NORMAL | 2021-05-19T10:46:44.086186+00:00 | 2022-08-15T11:41:32.430872+00:00 | 6,741 | false | ### **Approach 1: Sliding Window**\n\n**Implementation**\n```\npublic int LengthOfLongestSubstring(string s) {\n\tvar letters = new Dictionary<char, int>(); // key:letter, val: latest index\n\tint maxCount = 0, left = 0, right;\n\n\tfor (right = 0; right < s?.Length; right++) {\n\t\tchar letter = s[right];\n\n\t\tif (l... | 33 | 0 | ['Sliding Window', 'C#'] | 4 |
longest-substring-without-repeating-characters | Java simple | java-simple-by-georgcantor-gy0d | \npublic int lengthOfLongestSubstring(String s) {\n int start = 0;\n int end = 0;\n int max = 0;\n Set<Character> set = new HashSet< | GeorgCantor | NORMAL | 2021-01-30T10:37:24.695595+00:00 | 2022-03-01T15:36:55.129271+00:00 | 4,261 | false | ```\npublic int lengthOfLongestSubstring(String s) {\n int start = 0;\n int end = 0;\n int max = 0;\n Set<Character> set = new HashSet<>();\n while (end < s.length()) {\n if (!set.contains(s.charAt(end))) {\n set.add(s.charAt(end));\n end++;\n ... | 33 | 2 | ['Java'] | 8 |
longest-substring-without-repeating-characters | C++ | Short & Easy Solutions ✅ | c-short-easy-solutions-by-prantik0128-5kq1 | Please upvote if you like the solution & post :)\n\nSliding-window + Unordered_set Solution:\n\nclass Solution {\npublic:\n\tint lengthOfLongestSubstring(string | prantik0128 | NORMAL | 2022-06-10T03:49:15.789465+00:00 | 2022-06-10T04:19:10.484451+00:00 | 3,404 | false | **`Please upvote if you like the solution & post :)`**\n\n**`Sliding-window + Unordered_set` Solution:**\n```\nclass Solution {\npublic:\n\tint lengthOfLongestSubstring(string s) {\n\t\tunordered_set<char> set;\n\t\tint i = 0, j = 0, n = s.size(), ans = 0;\n\t\twhile(j<n){\n\t\t\tif(set.find(s[j]) == set.end()){ //If t... | 32 | 3 | ['C', 'Sliding Window'] | 4 |
longest-substring-without-repeating-characters | ✅ [Python] Simple Solution w/ Explanation | Brute-Force + Sliding Window | python-simple-solution-w-explanation-bru-75l4 | We are given a string s. We need to find the length of the longest substring without repeating characters.\n\n\n\u2705 Solution I - Brute-Force [Accepted]\n\nSt | r0gue_shinobi | NORMAL | 2022-06-10T02:08:17.743152+00:00 | 2022-06-10T02:48:50.359521+00:00 | 5,381 | false | We are given a string `s`. We need to find the length of the **longest substring** without repeating characters.\n___\n___\n\u2705 **Solution I - Brute-Force [Accepted]**\n\nStarting with each index, we can check all substrings till we find a repeating character.\n\n```python\nclass Solution:\n def lengthOfLongestSu... | 32 | 1 | ['Two Pointers', 'Sliding Window', 'Python', 'Python3'] | 6 |
longest-substring-without-repeating-characters | O(n) time O(1) space solution using Kadane's algo in Java | on-time-o1-space-solution-using-kadanes-9zctm | Idea is that, while we traverse form left to right if we see a character at position j is a duplicate of a character at a position i < j on the left then we kno | zahid2 | NORMAL | 2015-10-06T22:54:31+00:00 | 2018-09-22T23:39:15.493105+00:00 | 12,668 | false | Idea is that, while we traverse form left to right if we see a character at position j is a duplicate of a character at a position i < j on the left then we know that we can't start the substring from i anymore. So, we need to start a new substring from i+1 position. While doing this we also need to update the length o... | 31 | 2 | [] | 16 |
longest-substring-without-repeating-characters | LengthOfLongestSubstring in C# using Sliding window approach. O(n) | lengthoflongestsubstring-in-c-using-slid-wojh | \n# Approach\n Describe your approach to solving the problem. \nThis solution uses a sliding window approach to find the longest\nsubstring without repeating ch | daniel-m | NORMAL | 2023-01-26T18:06:04.036467+00:00 | 2023-01-26T18:06:04.036524+00:00 | 8,135 | false | \n# Approach\n<!-- Describe your approach to solving the problem. -->\nThis solution uses a sliding window approach to find the longest\nsubstring without repeating characters.\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(min(n, m))$$\n<!... | 29 | 0 | ['C#'] | 5 |
longest-substring-without-repeating-characters | O(n) JavaScript + TypeScript with detailed explanatory comments | on-javascript-typescript-with-detailed-e-emfg | \n// We can solve this using a dynamic "sliding window" that \n// shrinks or grows whenever certain conditions are met\n\nconst lengthOfLongestSubstring = funct | christopher4lis | NORMAL | 2021-10-19T20:11:06.493616+00:00 | 2021-10-19T20:11:31.351283+00:00 | 4,097 | false | ```\n// We can solve this using a dynamic "sliding window" that \n// shrinks or grows whenever certain conditions are met\n\nconst lengthOfLongestSubstring = function(characters: string) {\n // Setting to 0 takes care of the edge case where "characters" is \'\'\n let length = 0\n \n // Map will store each c... | 29 | 0 | ['Sliding Window', 'TypeScript', 'JavaScript'] | 7 |
longest-substring-without-repeating-characters | C++ | O(N) | Using Frequency Map | | c-on-using-frequency-map-by-persistentbe-b5tx | Use Sliding Window approach using frequency map.\n As soon as frequency of any character becomes more than one, contract window till frequency of that character | persistentBeast | NORMAL | 2022-06-10T06:11:33.175975+00:00 | 2022-06-11T07:45:14.350588+00:00 | 4,265 | false | * Use Sliding Window approach using frequency map.\n* As soon as frequency of any character becomes more than one, contract window till frequency of that character reduces to 1.\n* Window is marked by `st` and `end` index.\n* Update `ans` at each `end` index.\n* **TC : O(N)**\n```\nclass Solution {\npublic: \n ... | 28 | 1 | ['C', 'Sliding Window'] | 3 |
longest-substring-without-repeating-characters | ✔️ 100% Fastest TypeScript Solution | 100-fastest-typescript-solution-by-serge-bg9p | \nfunction lengthOfLongestSubstring(s: string): number {\n const scanner: string[] = []\n let longest = 0\n\n for (const char of s) {\n const possibleInde | sergeyleschev | NORMAL | 2022-03-27T12:34:35.844577+00:00 | 2022-03-30T16:44:12.017654+00:00 | 7,959 | false | ```\nfunction lengthOfLongestSubstring(s: string): number {\n const scanner: string[] = []\n let longest = 0\n\n for (const char of s) {\n const possibleIndex = scanner.indexOf(char)\n\n if (possibleIndex !== -1) { scanner.splice(0, possibleIndex + 1) }\n scanner.push(char)\n longest = Math.max(longest, ... | 28 | 1 | ['TypeScript', 'JavaScript'] | 6 |
longest-substring-without-repeating-characters | C++/Java/Python/JavaScript || ✅✅Sliding Window || ✅🔥🚀100% Solution Explained | cjavapythonjavascript-sliding-window-100-6trh | Intuition:\n\nThe problem requires us to find the length of the longest substring without repeating characters in a given string. We can use a sliding window te | devanshupatel | NORMAL | 2023-05-07T13:58:17.058470+00:00 | 2023-05-07T13:58:17.058507+00:00 | 21,299 | false | # Intuition:\n\nThe problem requires us to find the length of the longest substring without repeating characters in a given string. We can use a sliding window technique to keep track of the longest substring without repeating characters. \n\n# Approach:\n1. Initialize ans=0, l=0, r=0.\n2. Create a map of size 256 to s... | 27 | 0 | ['Sliding Window', 'Python', 'C++', 'Java', 'JavaScript'] | 4 |
longest-substring-without-repeating-characters | Intuitive JavaScript solution with Sliding Window | intuitive-javascript-solution-with-slidi-qxi9 | \n/**\n * @param {string} s\n * @return {number}\n */\nvar lengthOfLongestSubstring = function(s) {\n const set = new Set();\n let longest = 0;\n let i | dawchihliou | NORMAL | 2020-04-13T09:31:54.691407+00:00 | 2020-04-13T09:31:54.691456+00:00 | 2,840 | false | ```\n/**\n * @param {string} s\n * @return {number}\n */\nvar lengthOfLongestSubstring = function(s) {\n const set = new Set();\n let longest = 0;\n let i = 0;\n let j = 0;\n /**\n * The goal is to anchor i and find the longest range of [i, j].\n * When s[i, j] has a duplicate letter, we remove s... | 27 | 0 | ['Sliding Window', 'JavaScript'] | 1 |
longest-substring-without-repeating-characters | Simple Python3 Solution using Sliding window || Beats 99% || 💻🧑💻🤖 | simple-python3-solution-using-sliding-wi-mx3s | \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={ | Abhishek2708 | NORMAL | 2023-09-08T16:59:29.890257+00:00 | 2023-09-13T11:21:57.207303+00:00 | 3,404 | false | \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]]+... | 26 | 0 | ['Python3'] | 3 |
longest-substring-without-repeating-characters | Python. Cool & easy solution. O(n) time. O(1) space. | python-cool-easy-solution-on-time-o1-spa-ctfb | \tclass Solution:\n\t\tdef lengthOfLongestSubstring(self, s: str) -> int:\n\t\t\tcharacters = set()\n\t\t\tleft = right = ans = 0\n\t\t\tlength = len(s)\n\t\t\t | m-d-f | NORMAL | 2021-01-07T08:58:48.325249+00:00 | 2021-01-07T08:58:48.325304+00:00 | 3,522 | false | \tclass Solution:\n\t\tdef lengthOfLongestSubstring(self, s: str) -> int:\n\t\t\tcharacters = set()\n\t\t\tleft = right = ans = 0\n\t\t\tlength = len(s)\n\t\t\t\n\t\t\twhile right < length:\n\t\t\t\tif s[right] in characters:\n\t\t\t\t\tcharacters.remove(s[left])\n\t\t\t\t\tleft += 1\n\t\t\t\telse:\n\t\t\t\t\tcharacter... | 26 | 3 | ['Python', 'Python3'] | 6 |
longest-substring-without-repeating-characters | c# | c-by-csharp-3i9x | ```\npublic class Solution {\n public int LengthOfLongestSubstring(string s) {\n if (s == null || s == String.Empty)\n return 0;\n\ | csharp | NORMAL | 2020-06-02T07:04:35.480255+00:00 | 2020-06-02T07:04:35.480294+00:00 | 5,392 | false | ```\npublic class Solution {\n public int LengthOfLongestSubstring(string s) {\n if (s == null || s == String.Empty)\n return 0;\n\n HashSet<char> set = new HashSet<char>();\n int currentMax = 0,\n i = 0,\n j = 0;\n\n while (j <... | 26 | 4 | [] | 0 |
longest-substring-without-repeating-characters | Swift, faster than 79.38% of swift submissions | swift-faster-than-7938-of-swift-submissi-u3ij | O(n)\n\nclass Solution {\n func lengthOfLongestSubstring(_ s: String) -> Int {\n var longest = 0, startIndex = 0\n var charMap: [Character: Int | rshev | NORMAL | 2020-03-07T18:07:23.154515+00:00 | 2020-03-07T18:07:23.154547+00:00 | 2,887 | false | O(n)\n```\nclass Solution {\n func lengthOfLongestSubstring(_ s: String) -> Int {\n var longest = 0, startIndex = 0\n var charMap: [Character: Int] = [:]\n\n for (index, char) in s.enumerated() {\n if let foundIndex = charMap[char] {\n startIndex = max(foundIndex+1, sta... | 26 | 0 | ['Swift'] | 3 |
longest-substring-without-repeating-characters | Java concise HashMap solution. | java-concise-hashmap-solution-by-oldcodi-clr7 | \n public int lengthOfLongestSubstring(String s) {\n int ret = 0;\n Map<Character, Integer> map = new HashMap<>();\n for (int i = 0, sta | oldcodingfarmer | NORMAL | 2016-04-10T13:33:07+00:00 | 2016-04-10T13:33:07+00:00 | 4,867 | false | \n public int lengthOfLongestSubstring(String s) {\n int ret = 0;\n Map<Character, Integer> map = new HashMap<>();\n for (int i = 0, start = 0; i < s.length(); i++) {\n char c = s.charAt(i);\n if (map.containsKey(c)) \n start = Math.max(map.get(c)+1, star... | 26 | 4 | ['Java'] | 0 |
longest-substring-without-repeating-characters | Simple and fast C++ solution | simple-and-fast-c-solution-by-shubit-dcl8 | Intuition\nWe iterate over the input and maintain a [start, i] interval that only contains unique characters. For every character s[i] we first advance start un | shubit | NORMAL | 2023-04-20T18:05:44.017880+00:00 | 2023-04-20T18:05:44.017919+00:00 | 6,056 | false | # Intuition\nWe iterate over the input and maintain a $$[start, i]$$ interval that only contains unique characters. For every character $$s[i]$$ we first advance $$start$$ until $$[start, i-1]$$ doesn\'t $$s[i]$$. The longest $$i-start+1$$ is the longest substring.\n\n# Complexity\n- Time complexity: $$O(n)$$ (iterate ... | 25 | 0 | ['C++'] | 9 |
longest-substring-without-repeating-characters | Python Easy 2 approaches ✅ | python-easy-2-approaches-by-constantine7-zd7z | Sliding Window - Counter\n\nThis approach uses counter variable to track number of characters in a sliding window. Whenever we encounter a state where the windo | constantine786 | NORMAL | 2022-06-10T00:29:20.091247+00:00 | 2022-06-10T00:29:20.091276+00:00 | 3,919 | false | 1. ## **Sliding Window - Counter**\n\nThis approach uses `counter` variable to track number of characters in a sliding window. Whenever we encounter a state where the window becomes invalid due to number of characters(count of any character > 1), we would update the left bound of the new valid window.\n\n```\nclass Sol... | 25 | 1 | ['Python', 'Python3'] | 3 |
longest-substring-without-repeating-characters | [Python] One pass - Clean & Concise | python-one-pass-clean-concise-by-hiepit-prsa | Python\npython\nclass Solution:\n def lengthOfLongestSubstring(self, s: str) -> int:\n ans = 0\n l = 0\n lastIndex = [-1] * 128\n | hiepit | NORMAL | 2019-04-03T08:31:06.097723+00:00 | 2021-09-06T08:27:22.165258+00:00 | 558 | false | **Python**\n```python\nclass Solution:\n def lengthOfLongestSubstring(self, s: str) -> int:\n ans = 0\n l = 0\n lastIndex = [-1] * 128\n for r, c in enumerate(s):\n l = max(l, lastIndex[ord(c)] + 1)\n lastIndex[ord(c)] = r\n ans = max(ans, r - l + 1)\n ... | 25 | 0 | [] | 1 |
longest-substring-without-repeating-characters | C Super-Simple Clean Solution 0ms | c-super-simple-clean-solution-0ms-by-yeh-n2po | \nint lengthOfLongestSubstring(char * s){\n /*letter_map is to keep track if we saw this character in this substring*/\n int letter_map[128] = {0}, res = | yehudisk | NORMAL | 2021-01-07T11:53:24.643225+00:00 | 2021-01-07T11:53:49.291239+00:00 | 2,726 | false | ```\nint lengthOfLongestSubstring(char * s){\n /*letter_map is to keep track if we saw this character in this substring*/\n int letter_map[128] = {0}, res = 0;\n char* start = s, *end = s;\n \n while (*end) {\n /* If we reached a letter we saw already - check max length and start a new substring*/... | 24 | 0 | ['C'] | 2 |
longest-substring-without-repeating-characters | Python | Easy Solution✅ | python-easy-solution-by-gmanayath-5qq5 | \n# Code\u2705\n\nclass Solution:\n def lengthOfLongestSubstring(self, s: str) -> int:\n output = 0\n count = {}\n pos = -1\n for | gmanayath | NORMAL | 2022-11-10T11:55:39.057941+00:00 | 2022-12-22T16:42:37.829264+00:00 | 10,839 | false | \n# Code\u2705\n```\nclass Solution:\n def lengthOfLongestSubstring(self, s: str) -> int:\n output = 0\n count = {}\n pos = -1\n for index, letter in enumerate(s):\n if letter in count and count[letter] > pos:\n pos = count[letter]\n count[letter] = in... | 23 | 0 | ['Hash Table', 'Sliding Window', 'Python', 'Python3'] | 4 |
longest-substring-without-repeating-characters | My O(n) solution , runtime: 5ms | my-on-solution-runtime-5ms-by-loggerhead-6kcj | int lengthOfLongestSubstring(char *s) {\n int m[129] = {0};\n int i, j;\n int cnt = 0, pre = 0;\n int max = 0;\n int c;\n | loggerhead | NORMAL | 2015-02-11T11:36:09+00:00 | 2018-10-11T23:34:01.357458+00:00 | 8,074 | false | int lengthOfLongestSubstring(char *s) {\n int m[129] = {0};\n int i, j;\n int cnt = 0, pre = 0;\n int max = 0;\n int c;\n \n for (i = 0; c = s[i]; i++) {\n if (pre < m[c]) {\n if (max < cnt)\n max = cnt;\n \n ... | 23 | 1 | [] | 8 |
longest-substring-without-repeating-characters | Short'n'Sweet Python solution, beats 99% | shortnsweet-python-solution-beats-99-by-g6swo | class Solution(object):\n def lengthOfLongestSubstring(self, s):\n last, res, st = {}, 0, 0\n for i, v in enumerate(string):\n | agave | NORMAL | 2016-05-30T12:31:58+00:00 | 2018-10-12T21:47:07.241576+00:00 | 7,100 | false | class Solution(object):\n def lengthOfLongestSubstring(self, s):\n last, res, st = {}, 0, 0\n for i, v in enumerate(string):\n if v not in last or last[v] < st:\n res = max(res, i - st + 1)\n else:\n st = last[v] + 1\n ... | 23 | 0 | [] | 4 |
longest-substring-without-repeating-characters | Java || HashSet || Sliding Window | java-hashset-sliding-window-by-emirhanoz-ims9 | Intuition\nUpon encountering this problem, my initial instinct is to utilize the sliding window technique to identify the length of the longest substring withou | emirhanozcan | NORMAL | 2023-08-30T05:44:29.910453+00:00 | 2023-08-30T05:44:29.910482+00:00 | 985 | false | # Intuition\nUpon encountering this problem, my initial instinct is to utilize the sliding window technique to identify the length of the longest substring without repeating characters.\n\n# Approach\nMy approach to tackling this problem involves implementing the sliding window technique to ascertain the length of the ... | 22 | 0 | ['Java'] | 2 |
longest-substring-without-repeating-characters | Python solution || simple and fast || 44ms (99%) || 12.9MB (100%) | python-solution-simple-and-fast-44ms-99-hnz89 | If you find it nice, please upvote!\n\n\ndef lengthOfLongestSubstring(s: str):\n max_len = 0\n sub = \'\'\n \n for l in s:\n if l in sub:\n | mbronis | NORMAL | 2019-12-28T00:11:06.402618+00:00 | 2019-12-28T00:11:06.402655+00:00 | 1,741 | false | If you find it nice, please upvote!\n\n```\ndef lengthOfLongestSubstring(s: str):\n max_len = 0\n sub = \'\'\n \n for l in s:\n if l in sub:\n sub = sub[sub.find(l)+1:] \n sub += l\n if len(sub) > max_len:\n max_len = len(sub)\n \n return max_l... | 22 | 0 | ['Python'] | 2 |
longest-substring-without-repeating-characters | Python solution | python-solution-by-zitaowang-2msp | We initialize the result res = 0, and two pointers j = 0, and i = 0. We initialize a dictionary dic which maps every element in s[:i+1] to its index of rightmos | zitaowang | NORMAL | 2019-02-13T23:25:29.033866+00:00 | 2019-02-13T23:25:29.033927+00:00 | 5,121 | false | We initialize the result `res = 0`, and two pointers `j = 0`, and `i = 0`. We initialize a dictionary `dic` which maps every element in `s[:i+1]` to its index of rightmost occurrence in `s[:i+1]`. Then we iterate `i` over `range(len(s))`, if `s[i]` is not in `dic`, we add it to `dic`: `dic[s[i]] = i`; Otherwise, we mov... | 22 | 0 | [] | 5 |
longest-substring-without-repeating-characters | ✅ [Rust] 0 ms, no HashMap, simply use position differences (with detailed comments) | rust-0-ms-no-hashmap-simply-use-position-u33q | This solution employs simple calculation of position differences for repeated characters. It demonstrated 0 ms runtime (100.00%) and used 2.1 MB memory (97.34%) | stanislav-iablokov | NORMAL | 2022-09-16T14:12:16.585992+00:00 | 2022-10-23T12:57:31.718011+00:00 | 1,649 | false | This [solution](https://leetcode.com/submissions/detail/801296870/) employs simple calculation of position differences for repeated characters. It demonstrated **0 ms runtime (100.00%)** and used **2.1 MB memory (97.34%)**. Detailed comments are provided.\n\n**IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n```\nimpl Solu... | 21 | 0 | ['Rust'] | 1 |
longest-substring-without-repeating-characters | Simplest way (with explanation) [97% faster] | simplest-way-with-explanation-97-faster-98xnj | \nclass Solution:\n def lengthOfLongestSubstring(self, s: str) -> int:\n \n string = s\n \n max_length = 0 # we set max_leng | tony_stark_47 | NORMAL | 2021-10-17T16:56:06.255314+00:00 | 2021-10-17T17:17:07.790113+00:00 | 1,805 | false | ```\nclass Solution:\n def lengthOfLongestSubstring(self, s: str) -> int:\n \n string = s\n \n max_length = 0 # we set max_length to 0 because string may be empty.\n seen_character = \'\' # a empty string to store the character that we have already seen.\n \n for... | 21 | 0 | ['Python', 'Python3'] | 5 |
longest-substring-without-repeating-characters | Golang solution | golang-solution-by-linfongi-bi7s | func lengthOfLongestSubstring(str string) int {\n \tm, max, left := make(map[rune]int), 0, 0\n \tfor idx, c := range str {\n \t\tif _, okay := m[c]; ok | linfongi | NORMAL | 2016-03-28T01:40:16+00:00 | 2016-03-28T01:40:16+00:00 | 3,277 | false | func lengthOfLongestSubstring(str string) int {\n \tm, max, left := make(map[rune]int), 0, 0\n \tfor idx, c := range str {\n \t\tif _, okay := m[c]; okay == true && m[c] >= left {\n \t\t\tif idx-left > max {\n \t\t\t\tmax = idx - left\n \t\t\t}\n \t\t\tleft = m[c] + 1\n \t\t}\n \t\tm[c] =... | 20 | 9 | ['Go'] | 1 |
longest-substring-without-repeating-characters | Golang: explanation (100% speed & memory) | golang-explanation-100-speed-memory-by-a-40rw | dict is our dictionary of previously encountered characters\n2. Increment i and use character s[i] as index in dict to set value to true: dict[s[i]] = true\n3. | andnik | NORMAL | 2019-12-01T19:43:54.994509+00:00 | 2019-12-01T19:43:54.994566+00:00 | 3,821 | false | 1. `dict` is our dictionary of previously encountered characters\n2. Increment `i` and use character `s[i]` as index in `dict` to set value to `true`: `dict[s[i]] = true`\n3. With each step we increment `length` and compare it to `max` value and set `max = length` if length now bigger.\n4. When we face character we alr... | 19 | 1 | ['Go'] | 1 |
longest-substring-without-repeating-characters | Simple java solution | simple-java-solution-by-band-bfp6 | public class Solution {\n public int lengthOfLongestSubstring(String s) {\n Map<Character,Integer> indices = new HashMap<Character,Integer>(); | band | NORMAL | 2015-10-23T02:57:23+00:00 | 2018-09-10T18:31:08.535095+00:00 | 6,123 | false | public class Solution {\n public int lengthOfLongestSubstring(String s) {\n Map<Character,Integer> indices = new HashMap<Character,Integer>();\n int length = 0;\n int start = -1;\n int end = 0;\n for(end=0; end < s.length(); end++){\n char... | 19 | 0 | ['Java'] | 4 |
longest-substring-without-repeating-characters | python | python-by-vote4-tbek | \ndef lengthOfLongestSubstring(self, s: str) -> int:\n maxLength = 0\n dict = {}\n\n i,j = 0,0\n n = len(s)\n\n while(j < n): | vote4 | NORMAL | 2022-12-17T06:47:16.456319+00:00 | 2022-12-17T06:47:16.456351+00:00 | 3,462 | false | ```\ndef lengthOfLongestSubstring(self, s: str) -> int:\n maxLength = 0\n dict = {}\n\n i,j = 0,0\n n = len(s)\n\n while(j < n):\n c = s[j] \n \n dict[c] = 1 if not c in dict else dict[c] + 1\n \n \n if dict[c] > 1:... | 18 | 0 | [] | 1 |
longest-substring-without-repeating-characters | [Fastest Solution Explained][0ms][100%] O(n)time complexity O(n)space complexity | fastest-solution-explained0ms100-ontime-uwfs9 | \n(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\nTake care brother, | darian-catalin-cucer | NORMAL | 2022-08-05T14:56:08.986727+00:00 | 2022-08-05T14:56:08.986775+00:00 | 5,349 | false | \n(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, ***please upvote*** this post.)\n***Take care brother, peace, love!***\n\n```\n```\n\nThe best result for the code below is ***0ms / 3.27MB*** (beats 99.04% / 90.42%).\n* *** Java ***\n\n```\n\npublic int l... | 18 | 1 | ['Swift', 'C', 'PHP', 'Python', 'C++', 'Java', 'Python3', 'Kotlin', 'JavaScript'] | 2 |
longest-substring-without-repeating-characters | 8 Lines C++ Solution | 8-lines-c-solution-by-xiaoli727-2g8t | Description\nLongest Substring Without Repeating Characters: Given a string s, find the length of the longest substring without repeating characters.\nExample:\ | xiaoli727 | NORMAL | 2021-08-04T16:22:12.554130+00:00 | 2021-08-04T16:23:03.805321+00:00 | 2,247 | false | **Description**\n[Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/): Given a string `s`, find the length of the **longest substring** without repeating characters.\nExample:\n```\nInput: s = "pwwkew"\nOutput: 3\nExplanation: The answer is "wke... | 18 | 0 | ['C'] | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.