Strings Flashcards
- Longest Substring Without Repeating Characters
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 the length of 1.
Example 3:
Input: s = “pwwkew”
Output: 3
Explanation: The answer is “wke”, with the length of 3.
Notice that the answer must be a substring, “pwke” is a subsequence and not a substring.
Example 4:
Input: s = “”
Output: 0
Base concept: sliding window
- Initialize hash set
- Initialize left pointer
- Initialize max length var to return
- Create for loop in range of length of
s
with pointerr
- Create nested while loop that checks if current char(using index r) is in hash set
- Keep removing from chars from the hash set, iterating from through
s
with index of left pointer (incrementing by 1) until the current value is no longer found - Add the current value to hash set
- Find max by taking max of max length var and (r - l + 1)
- Longest Repeating Character Replacement
https://leetcode.com/problems/longest-repeating-character-replacement/
- Valid Anagram
https://leetcode.com/problems/valid-anagram/
- Group Anagrams
https://leetcode.com/problems/group-anagrams/
- Valid Parentheses
https://leetcode.com/problems/valid-parentheses/
- Valid Palindrome
https://leetcode.com/problems/valid-palindrome/
- Longest Palindromic Substring
https://leetcode.com/problems/longest-palindromic-substring/
- Palindromic Substrings
https://leetcode.com/problems/palindromic-substrings/