array string Pattern
49 problems
Pattern pages help build reusable solving frames. Identify signals first, then explain state, transition, and edge handling.
Recognition Signals
- Do you understand how to handle edge cases like when there is no common prefix?
- Can you describe the trade-offs between vertical scanning and horizontal scanning?
- Able to explain space distribution in detail.
Solve Flow
- 1. Define the active state/window.
- 2. Update state while preserving invariants.
- 3. Validate with edge-heavy examples.
Common Misses
- Failing to handle the case where no common prefix exists, returning an empty string instead of a valid result.
- Incorrectly distributing spaces when the number of spaces doesn't divide evenly.
- Not using bitwise operations correctly, leading to inefficient comparisons or incorrect results.
Recommended Ladder
Longest Common Prefix
Find the longest common prefix in an array of strings, returning an empty string if none exists.
Text Justification
Text Justification requires packing words into lines to match a specified width, ensuring even distribution of spaces.
Maximum Product of Word Lengths
The problem requires finding the maximum product of lengths of two words from an array, where the words don't share comm…
Remove Comments
Remove comments from a given C++ program source array, handling line and block comments.
Number of Lines To Write String
Calculate how many lines are needed to write a string given individual letter widths, constrained to 100 pixels per line…
Shifting Letters
Given a string and a shift array, shift the first i+1 letters of the string as specified in the array.
Reorder Data in Log Files
Reorder Data in Log Files requires sorting letter-logs lexicographically while keeping digit-logs in original order for …
Delete Columns to Make Sorted
The 'Delete Columns to Make Sorted' problem asks to remove unsorted columns from a string array, ensuring all columns ar…
Satisfiability of Equality Equations
Determine if it's possible to assign values to variables such that all equations are satisfied based on equality and ine…
Stream of Characters
Implement a StreamChecker that detects if any suffix of a character stream matches a given list of words using efficient…
Remove Sub-Folders from the Filesystem
Remove sub-folders in a filesystem by filtering out folders nested inside other folders.
Print Words Vertically
Transform a string into vertical columns by arranging each word character in array positions while trimming trailing spa…
String Matching in an Array
Identify all strings in an array that appear as substrings of other strings, focusing on array and string matching patte…
Shuffle String
Reorder characters in a string using a given indices array to reconstruct the intended output efficiently and correctly.
Slowest Key
Determine which key had the longest press duration in a sequence using array indices and string mapping, resolving ties …
Check If Two String Arrays are Equivalent
Determine if two string arrays form identical strings by concatenating elements in order, handling subtle array-length m…
Minimum Number of Operations to Move All Balls to Each Box
Solve the problem of finding the minimum operations to move balls to each box using an efficient approach with arrays an…
Count Items Matching a Rule
Count Items Matching a Rule is an easy problem that tests array and string manipulation with conditions based on specifi…
Truncate Sentence
Truncate a sentence to contain only the first k words by converting it into an array of words.
Number of Strings That Appear as Substrings in Word
Count how many strings in an array appear as substrings within a given word by checking each pattern individually.
Find the Kth Largest Integer in the Array
This problem asks to find the kth largest integer in an array of string numbers, highlighting sorting and string-based c…
Final Value of Variable After Performing Operations
Compute the final value of X by simulating each string operation in the array sequentially with careful tracking.
Maximum Number of Words Found in Sentences
Find the maximum number of words in a single sentence from an array of sentences using array and string processing techn…
Counting Words With a Given Prefix
Count how many words in a list start with a given prefix.
Longest Substring of One Repeating Character
Solve Longest Substring of One Repeating Character by maintaining mergeable run information under character updates afte…
Count Prefixes of a Given String
Count Prefixes of a Given String is a problem that involves finding the number of string prefixes in an array that match…
Query Kth Smallest Trimmed Number
Solve the Query Kth Smallest Trimmed Number problem by efficiently trimming and sorting strings in an array to answer qu…
Shifting Letters II
Shift letters in a string using a sequence of range-based forward or backward operations efficiently with prefix sums.
Minimum Amount of Time to Collect Garbage
This problem asks you to find the minimum amount of time needed to collect all garbage in a city, focusing on array and …
Sum of Prefix Scores of Strings
The 'Sum of Prefix Scores of Strings' problem involves calculating prefix scores for strings based on their occurrences …
Determine if Two Events Have Conflict
Compare two same-day time intervals and check whether their inclusive endpoints overlap after converting HH:MM strings i…
Words Within Two Edits of Dictionary
Identify all words in queries that can match dictionary entries with at most two character changes efficiently using arr…
Maximum Value of a String in an Array
The problem requires finding the maximum value of alphanumeric strings in an array based on length or numeric value.
Shortest Distance to Target String in a Circular Array
Find the shortest distance to a target string in a circular array with either left or right movement options.
Count Vowel Strings in Ranges
Count the number of strings that start and end with a vowel in given ranges within an array of words.
Count the Number of Vowel Strings in Range
Count the Number of Vowel Strings in Range asks to count vowel strings in a subarray of a given word list.
Number of Senior Citizens
Determine how many passengers are over 60 years old based on their compressed details in an array of strings.
Split Strings by Separator
Split Strings by Separator requires iterating through an array of strings and splitting each by a given separator charac…
Check if a String Is an Acronym of Words
Check if a string can be formed by concatenating the first letters of each word in a given list.
Find Words Containing Character
Identify all indices of words containing a specific character using array and string traversal techniques efficiently.
Minimum Cost to Convert String I
This problem asks to calculate the minimum cost to convert a string from source to target using specific character trans…
Count Prefix and Suffix Pairs I
Count all index pairs where one word is both a prefix and suffix of another, using efficient array and string checks.
Count Prefix and Suffix Pairs II
Count the number of index pairs in a string array where one word is both a prefix and suffix of another using array and …
Longest Common Suffix Queries
Find the index of the string in wordsContainer with the longest common suffix for each query efficiently using array and…
Snake in Matrix
Solve the Snake in Matrix problem by simulating the snake's movement in a grid based on a series of directional commands…
Shift Distance Between Two Strings
Find the minimum cost of transforming one string into another, considering operations between characters.
Longest Common Prefix of K Strings After Removal
Find the longest common prefix length of k strings after removing an element in the array.
Count Cells in Overlapping Horizontal and Vertical Substrings
Efficiently count grid cells appearing in both horizontal and vertical occurrences of a given string pattern using array…
Longest Common Prefix Between Adjacent Strings After Removals
Given an array of strings, find the longest common prefix length between adjacent strings after removals at each index.