FastPrepMinimum Rotations for the Longest Common Prefix
Problems/Minimum Rotations for the Longest Common Prefix

Minimum Rotations for the Longest Common Prefix

Wells Fargo logoWells Fargo● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives both optimization priorities, how a rotation works, the result when nothing matches, and two examples. It leaves out the limits. Our version is about 99% the same as the reported question.

You are given two nonempty strings fixed and rotating. The first string never changes.

In one rotation of rotating, move its first character to the end or move its last character to the front. You may perform either operation any number of times.

First maximize the length of the common prefix between fixed and the rotated string. Among all rotations that achieve this maximum length, return the minimum number of rotations. If the maximum common-prefix length is 0, return -1.

Function

minimumRotationsForLongestPrefix(fixed: String, rotating: String) → int

Examples

Example 1

fixed = "fm47abcde"rotating = "47ghijfm"return = 2

Move m and then f from the end to the front. The rotated string starts with fm47, the longest possible common prefix.

Example 2

fixed = "abcde"rotating = "cabfg"return = 1

Move c from the front to the end. The strings then share prefix ab.

Example 3

fixed = "abc"rotating = "xyz"return = -1

No rotation starts with a, so no nonempty common prefix exists.

Example 4

fixed = "hello"rotating = "hello"return = 0

The unrotated strings already have the longest possible prefix.

Constraints

  • 1 <= fixed.length, rotating.length <= 2 * 10^5.
  • Both strings contain visible ASCII characters.

More Wells Fargo Online Assessment questions

  • Server Upgrade PlanningOA · Seen Nov 2026
  • Student and Course EnrollmentOA · Seen Nov 2026
  • Bond Interest Summary Above 3%OA · Seen Oct 2026
  • Count Phrases Formed by Anagram ReplacementOA · Seen Oct 2026
  • Event Statistics AggregatorOA · Seen Sep 2026
  • Ordered Deployment Configuration ValidatorOA · Seen Sep 2026
  • Longest Subsequence That Is a SubstringOA · Seen Jul 2026
  • Overloaded Game Account InventoriesOA · Seen Jul 2026
  • Count Server ReplacementsOA · PHONE SCREEN · Seen Feb 2026
  • Minimum Remaining LengthOA · PHONE SCREEN · Seen Feb 2026

Similar questions at other companies

  • Compare Version NumbersInMobi · PHONE SCREENInMobi interview questions
  • Polynomial CoefficientsShopify · OAShopify interview questions
  • Parse Router LogsIntuit · OAIntuit interview questions
  • Simplify a Quadratic ExpressionOpenAI · OAOpenAI interview questions
  • String CompressionAbridge · OAAbridge interview questions
  • K Smallest SubstringAkuna Capital · OAAkuna Capital interview questions
  • Format TextTikTok · OATikTok interview questions
  • Next Greater Element IIIThe Walt Disney Company · OAThe Walt Disney Company interview questions
  • Counting Binary Substrings (Backend)Canva · OACanva interview questions
  • Shortest SubstringRippling · OARippling interview questions

Interview reports that mention this question

  • Wells Fargo OA: What It Tests (2026)

Wells Fargo interview experiences

  • Wells Fargo SWE Intern OA and Interview Questions: 18 Experiences
All Wells Fargo interview questionsSee Wells Fargo hiring insights
Saved
class Solution {
    public int minimumRotationsForLongestPrefix(String fixed, String rotating) {
      // write your code here
    }
}
Checking account…