↓Skip to main content

String

LeetCode 1016: Binary String With Substrings Representing 1 To N
·3 mins
LeetCode Medium Sliding-Window String Bit-Manipulation Hash-Table
LeetCode 1016 note: s has at most 1000 characters, so there are few substrings of any fixed length and a large n must be False; checking from n downward fails fast, or extend up to 30 bits from each start to collect every value <= n
LeetCode 3794: Reverse String Prefix
·2 mins
LeetCode Easy Two-Pointers String
LeetCode 3794 note: one line with slicing; a hand-written two-pointer version must convert the string to a list first
LeetCode 1888: Minimum Number of Flips to Make the Binary String Alternating
·2 mins
LeetCode Medium Sliding-Window String Dynamic-Programming
LeetCode 1888 note: rotations become length-n windows over s + s; the window’s mismatches against 0101… are diff, and against 1010… they are n - diff
LeetCode 3694: Distinct Points Reachable After Substring Removal
·2 mins
LeetCode Medium Sliding-Window Prefix-Sum Hash-Table String
LeetCode 3694 note: the endpoint is the total displacement minus the removed segment’s displacement; a length-k window tracks that segment and each endpoint goes into a set
LeetCode 3750: Minimum Number of Flips to Reverse Binary String
·2 mins
LeetCode Easy Two-Pointers Bit-Manipulation String
LeetCode 3750 note: compare the binary string with its reverse bit by bit; the number of mismatches is the answer
LeetCode 3707: Equal Score Substrings
·2 mins
LeetCode Easy Prefix-Sum String
LeetCode 3707 note: accumulate the left score while scanning, with the right side as total minus left; scores are alphabet positions 1 to 26, not ord
LeetCode 394: Decode String
·2 mins
LeetCode Medium Stack String Recursion
LeetCode 394 note: on [ push the current string and count, on ] pop and combine; counts can have several digits
LeetCode 3703: Remove K-Balanced Substrings
·2 mins
LeetCode Medium Stack String Simulation
LeetCode 3703 note: repeated replace is O(n^2); a stack of (character, run length) removes k ( plus k ) as soon as they line up
LeetCode 2131: Longest Palindrome by Concatenating Two Letter Words
·2 mins
LeetCode Medium Greedy Hash-Table String Counting
LeetCode 2131 note: pair each word with its reverse on both sides; self-palindromes also pair with each other, and only one leftover can sit in the middle
LeetCode 2264: Largest 3-Same-Digit Number in String
·1 min
LeetCode Easy String
LeetCode 2264 note: there are only ten candidates, “000” to “999”, so check from “999” down whether each appears
LeetCode 22: Generate Parentheses
·2 mins
LeetCode Daily Medium String Backtracking Recursion Combinatorics Parentheses
Generating all valid parentheses combinations using backtracking approach
LeetCode 20: Valid Parentheses
·2 mins
LeetCode Daily Easy String Stack Data-Structures Parentheses Validation
Solving the Valid Parentheses problem using stack-based approach