FastPrepLongest Common Prefix Length
Problems/Longest Common Prefix Length

Longest Common Prefix Length

Visa logoVisa● EasyFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A November 16, 2019 Visa Senior Software Engineer online assessment report asks for the length of the longest prefix two strings share, and links the matching well-known idea. It leaves out limits, the alphabet, how letter case works, and a function signature. Our version spells those out.

You are given two strings a and b.

Return the length of their longest common prefix: the longest string that begins at index 0 in both inputs. Character comparisons are case-sensitive.

Function

longestCommonPrefixLength(a: String, b: String) → int

Examples

Example 1

a = "flower"b = "flow"return = 4

Both strings begin with flow, and the second string ends after four characters.

Example 2

a = "abc"b = "xyz"return = 0

The first characters differ, so the common prefix is empty.

Constraints

  • 0 <= a.length, b.length <= 105
  • The combined input length is at most 2 * 105.
  • Both strings contain printable ASCII characters.

More Visa Online Assessment questions

  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Lock CodeOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
  • Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
  • Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
  • Count Valid Space-Delimited WordsOA · Seen Oct 2026
  • Earliest Common Meeting StartOA · Seen Oct 2026
  • Maximum Index-Weighted Sum with Disjoint SwapsOA · Seen Oct 2026
  • Maximum Equalized Substrings After One Adjacent SwapOA · Seen Sep 2026

Similar questions at other companies

  • Minimum Changes for Distinct Adjacent CharactersHeadlands Technologies · OAHeadlands Technologies interview questions
  • Theme Park Shuttle Wait TimeAirbnb · OAAirbnb interview questions
  • REST API: Country CodesHackerRank · OAHackerRank interview questions
  • Fill One Exact-Length Binary WindowAmazon · OA
  • Remove Vowels from a StringHSBC · OAHSBC interview questions
  • Branch with the Most FilesCapital One · OACapital One interview questions
  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Maximum Ones After K OperationsGoldman Sachs · OAGoldman Sachs interview questions
  • Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
  • Robot Stops Left or Right (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public int longestCommonPrefixLength(String a, String b) {
        // Write your code here.
    }

}
Checking account…