FastPrepCommon Prefix Length Sums
Problems/Common Prefix Length Sums

Common Prefix Length Sums

Roblox logoRoblox● HardNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The candidate's screenshots add up, for each string, its longest common prefix with every suffix. They label the result int[] even though a 100000-character limit can go past 32 bits. Our version keeps that limit and uses 64-bit sums. Our version is about 100% the same as the reported question.

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

Interview reports that mention this question

  • Roblox New Grad Early OA Tasks: 10 Experiences (Part 7 of 7)
  • Roblox New Grad Engineer Rounds: 13 Experiences (Part 6 of 7)
  • Roblox New Grad HackerRank OA: 18 Experiences (Part 5 of 7)

Roblox interview experiences

  • Roblox New Grad CodeSignal Finals: 23 Experiences (Part 4 of 7)
  • Roblox New Grad Games and BQ: 25 Experiences (Part 3 of 7)
  • Roblox New Grad Coding Rounds: 23 Experiences (Part 2 of 7)
All Roblox interview questionsSee Roblox hiring insights
Saved
class Solution {
    public long[] commonPrefix(String[] inputs) {
        // write your code here
    }

}
Checking account…