Strings Flashcards

1
Q
  1. 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

A

Base concept: sliding window

  1. Initialize hash set
  2. Initialize left pointer
  3. Initialize max length var to return
  4. Create for loop in range of length of s with pointer r
  5. Create nested while loop that checks if current char(using index r) is in hash set
  6. 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
  7. Add the current value to hash set
  8. Find max by taking max of max length var and (r - l + 1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. Longest Repeating Character Replacement
A

https://leetcode.com/problems/longest-repeating-character-replacement/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. Valid Anagram
A

https://leetcode.com/problems/valid-anagram/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. Group Anagrams
A

https://leetcode.com/problems/group-anagrams/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. Valid Parentheses
A

https://leetcode.com/problems/valid-parentheses/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. Valid Palindrome
A

https://leetcode.com/problems/valid-palindrome/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. Longest Palindromic Substring
A

https://leetcode.com/problems/longest-palindromic-substring/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. Palindromic Substrings
A

https://leetcode.com/problems/palindromic-substrings/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly