↓Skip to main content

String

LeetCode 2730: Find the Longest Semi-Repetitive Substring
·2 mins
LeetCode Medium Sliding-Window String
LeetCode 2730 note: the window holds at most one adjacent equal pair; when a new pair arrives, shrink the left until the previous pair leaves
LeetCode 2516: Take K of Each Character From Left and Right
·2 mins
LeetCode Medium Sliding-Window Hash-Table String
LeetCode 2516 note: taking from both ends leaves a middle block in which each letter may appear at most total − k times; find the longest such window
LeetCode 3090: Maximum Length Substring With Two Occurrences
·1 min
LeetCode Easy Sliding-Window Hash-Table String
LeetCode 3090 note: a longest-window slide that shrinks the left whenever the newly added character appears more than twice
LeetCode 2024: Maximize the Confusion of an Exam
·2 mins
LeetCode Medium Sliding-Window String Binary-Search Prefix-Sum
LeetCode 2024 note: a window is valid when the rarer of T and F appears at most k times (flip all of them); shrink the left when it is not
LeetCode 1208: Get Equal Substrings Within Budget
·1 min
LeetCode Medium Sliding-Window String Binary-Search Prefix-Sum
LeetCode 1208 note: each position costs |s[i] - t[i]|, so the problem becomes the longest subarray with sum <= maxCost
LeetCode 1461: Check If a String Contains All Binary Codes of Size K
·2 mins
LeetCode Medium Hash-Table String Bit-Manipulation Rolling-Hash
LeetCode 1461 note: put every length-k substring in a set and check that its size reaches 2^k; the last start is len(s) - k
LeetCode 3800: Minimum Cost to Make Two Binary Strings Equal
·2 mins
LeetCode Medium Greedy String
LeetCode 3800 note: split mismatches into two kinds; pair different kinds with a swap, same kinds with cross + swap, flip any leftover, and compare each against two flips
LeetCode 3799: Word Squares II
·2 mins
LeetCode Medium Backtracking Enumeration String
LeetCode 3799 note: four nested levels pruned by corner letters; sorting the words first makes the output lexicographic
LeetCode 3798: Largest Even Number
·1 min
LeetCode Easy String
LeetCode 3798 note: parity depends only on the last digit, so just delete trailing 1s; keeping more digits is larger
LeetCode 2953: Count Complete Substrings
·3 mins
LeetCode Hard Sliding-Window Hash-Table String
LeetCode 2953 note: split where neighboring letters differ by more than 2; in each segment enumerate the number of distinct letters d, slide a fixed window of d × k, and track how many letters appear exactly k times
LeetCode 2269: Find the K-Beauty of a Number
·2 mins
LeetCode Easy Sliding-Window Math String
LeetCode 2269 note: convert the number to a string and check every length-k substring; 0 cannot be a divisor
LeetCode 2156: Find Substring With Given Hash Value
·3 mins
LeetCode Hard Sliding-Window Rolling-Hash String
LeetCode 2156 note: the first character has weight p^0, so sliding right to left needs only multiply by p, add the new character, and subtract the outgoing one times p^k; the modulus may not be prime, so no modular inverse