Common Prefix Length Sums
Updated
Problem statement
For each string s in inputs, consider every nonempty suffix s[i..], including s itself. Compute the length of its longest common prefix with the original string and add those lengths.
Return one sum per input string, in the same order. For example, ababaa has suffix-prefix lengths [6,0,3,0,1,1], summing to 11. For this exercise, use a signed 64-bit result for each string, resolving the source’s too-narrow return label without reducing its input bounds. Keep the input unchanged.
Function
commonPrefix(inputs: String[]) → long[]Examples
Example 1
inputs = ["abcabcd"]return = [10]The full string contributes 7 and suffix abcd contributes 3; all other suffixes contribute zero.
Example 2
inputs = ["ababaa","aa"]return = [11,3]The sums are 6+0+3+0+1+1=11 and 2+1=3.
Example 3
inputs = ["abcd"]return = [4]Only the original string has a nonempty common prefix with itself.
Constraints
1 <= inputs.length <= 10.1 <= inputs[i].length <= 100000.- Every character is a lowercase English letter.
- Return an array of signed 64-bit sums. A length-100000 all-equal string has sum
5000050000.
More Roblox Online Assessment questions
- Centered Block Placement QueriesOA · Seen Oct 2026
- Robot Navigation Around LasersOA · Seen Oct 2026
- Factory Batch Profit (Game Adaptation)OA · Seen Sep 2026
- Nested Recipe Blocks (Game Adaptation)OA · Seen Sep 2026
- Vehicle Builds for Required Terrain (Game Adaptation)OA · Seen Sep 2026
- Track Received Byte RangesOA · Seen Sep 2026
- Break a PalindromeOA · Seen Jun 2026
- Count Pairs Differing in One DigitOA · Seen Oct 2025
- Find Zero Cells in a 2×2 GridOA · Seen Oct 2025
- Cat Route Budget Planning (Game Adaptation)OA · Seen Aug 2025
Similar questions at other companies
- Incident MonitorStripe · OAStripe interview questions
- Binary Sorting Rounds After FlipsVisa · OAVisa interview questions
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Find Words That Can Be Formed by CharactersTabaPay · OA
- Earliest Time to Schedule a MeetingMathWorks · OAMathWorks interview questions
- Earliest Meeting Start on a 24-Hour ClockIMC Trading · OAIMC Trading interview questions
- Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Count One-Swap Number PairsCapital One · OACapital One interview questions
- Earliest Time to Schedule a MeetingMicrosoft · OAMicrosoft interview questions