Unaligned Dedupe
Updated
Problem statement
You are given n lowercase strings, each of length m. Choose a block length l with l >= k, and split every string from left to right into non-overlapping blocks of length l. The last block may be shorter.
A block can be replaced by a zero-cost reference when an identical earlier block exists either in the same string or in the immediately previous string. Blocks may occur at different block positions in those strings.
The saving contributed by a referenced block equals its number of characters. Find the block length that maximizes total savings. If several lengths tie, choose the smallest.
Return [best block length, maximum characters saved].
Function
unalignedDedupe(strings: String[], m: int, k: int) → int[]Examples
Example 1
strings = ["aand", "ndaa", "bend"]m = 4k = 1return = [1, 7]With block length 1, one character is saved in the first string, four in the second, and two in the third, for a total of 7.
Example 2
strings = ["abcdef", "defabc", "abdfea"]m = 6k = 2return = [3, 6]With block length 3, both blocks of the second string match blocks of the first string, saving 6 characters.
Constraints
- 1 <= n <= 1.5 * 106
- 1 <= m <= 1.5 * 106
- 1 <= n*m <= 1.5 * 106
- 1 <= k <= m
More Rubrik interview questions
- Colored Rooted TreeONSITE INTERVIEW · Seen Nov 2026
- Delete and Freeze GameOA · Seen Nov 2026
- Delete K Subsets for Maximum ScoreOA · Seen Nov 2026
- Distribute Elements Into Two Arrays IIOA · Seen Nov 2026
- Minimum Replacements to Sort the ArrayOA · Seen Nov 2026
- All Balanced Strings from Minimum Parenthesis InsertionsONSITE INTERVIEW · Seen Nov 2026
- Insert into a Left-Complete Binary TreeONSITE INTERVIEW · Seen Oct 2026
- Thread-Safe Request Counts by AttributeONSITE INTERVIEW · Seen Oct 2026
- Minimum Swaps To Binary PalindromeOA · Seen Apr 2026
- Get Minimum OperationsOA · Seen Nov 2024
Similar questions at other companies
- Perfect SubstringAXQ Capital · OA
- Maximum Valid Substring FrequencyMicrosoft · OAMicrosoft interview questions
- Longest Distinct StringSuperhuman · OASuperhuman interview questions
- Longest Substring Without Repeating CharactersAkuna Capital · OAAkuna Capital interview questions
- Perfect SubstringsVisa · OAVisa interview questions
- Vowel SubstringSnowflake · OASnowflake interview questions
- Count Distinct Fixed-Length SubstringsAdobe · OAAdobe interview questions
- Video ID Generation (Generic)TikTok · OATikTok interview questions
- Get Max OccurrencesIBM · OAIBM interview questions
- Find P-Matching ScoreAmazon · OA