FastPrepLongest Common Prefix
Problems/Longest Common Prefix

Longest Common Prefix

Wells Fargo logoWells Fargo● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names a medium task about the longest common prefix in an array of strings. The lowercase letters, non-empty input, limits, and the empty-result rule are our assumptions. Our version is about 88% the same as the reported question.

Given a nonempty array of lowercase strings words, return the longest string that is a prefix of every word.

If the words share no nonempty prefix, return the empty string.

Function

longestCommonPrefix(words: String[]) → String

Examples

Example 1

words = ["flower","flow","flight"]return = "fl"

All three words begin with fl, but their third characters differ.

Example 2

words = ["dog","racecar","car"]return = ""

The first characters are not all equal.

Example 3

words = ["interview","internet","internal"]return = "inter"

The shared prefix ends before the sixth character.

Constraints

  • 1 <= words.length <= 10^5.
  • 1 <= words[i].length <= 10^5.
  • The sum of all string lengths is at most 2 * 10^5.
  • Every string contains lowercase English letters.

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

  • Find a String Within One Mismatch of AllBarclays · OABarclays interview questions
  • Count Subarrays Matching a Comparison PatternTikTok · OATikTok interview questions
  • Earliest Time to Schedule a MeetingMathWorks · OAMathWorks interview questions
  • Earliest Meeting Start on a 24-Hour ClockIMC Trading · OAIMC Trading 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
  • Nested Recipe Blocks (Game Adaptation)Roblox · OARoblox interview questions
  • Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Maximum Equal Parts for PrefixesAmazon · OA

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 String longestCommonPrefix(String[] words) {
      // write your code here
    }
}
Checking account…