FastPrepCompare Two Version Strings
Problems/Compare Two Version Strings

Compare Two Version Strings

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem compares two version strings written with dots. A post from February 2022, by an engineer with ten or more years of experience who applied online in California and was turned down, links this classic task. It was the one practice-problem item of the opening phone round. An engineer from the UI side ran that round and also asked React questions. A later screen with a server-side engineer followed. The post gives only the link.

The rules here are those of the linked task: revisions are compared as whole numbers, leading zeros are ignored, and missing revisions count as 0. The difference is that a revision may have up to 40 digits, so it may not fit in a 64-bit integer. Our choices: 1 to 500 characters per version, revisions of up to 40 digits, and new examples.

Our version is about 90% the same as the reported question.

A version string is a list of revisions separated by dots, such as 2.10.0. Each revision is a whole number written in decimal, possibly with leading zeros (so 010 means 10).

Compare version1 and version2 revision by revision from the left, as numbers. If one version has fewer revisions, its missing revisions count as 0. Return 1 if version1 is larger at the first revision where they differ, -1 if version2 is larger there, and 0 if no revision differs.

A revision can have up to 40 digits, which is more than a 64-bit integer can hold.

Function

compareVersions(version1: String, version2: String) → int

Examples

Example 1

version1 = "3.14.0"version2 = "3.9"return = 1

The first revisions are equal (3 and 3). The second revisions are 14 and 9, and 14 is larger, so the first version is newer: return 1.

Example 2

version1 = "2.005.0.0"version2 = "2.5"return = 0

005 is the number 5, and the missing revisions of the second version count as 0. Both are 2, 5, 0, 0, so return 0.

Example 3

version1 = "7.2"version2 = "7.2.0.1"return = -1

The first three revisions match (7, 2, 0). The fourth is missing in the first version, so it counts as 0, which is less than 1: return -1.

Constraints

  • 1 <= version1.length, version2.length <= 500
  • version1 and version2 consist of digits and '.'.
  • Each version is one or more revisions joined by single dots (no dot at the start or the end, and no two dots in a row), and every revision has 1 to 40 digits.

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Longest Palindromic SubstringSiemens · PHONE SCREEN
  • Reverse Words in a StringAgoda · PHONE SCREENAgoda interview questions
  • Longest Palindromic SubstringIBM · PHONE SCREENIBM interview questions
  • Shortest Deletion for a Distinct RemainderGoogle · PHONE SCREENGoogle interview questions
  • Shortest Way to Form a Target StringPinterest · PHONE SCREENPinterest interview questions
  • Validate a Palindrome After Limited DeletionsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
  • Snake-Case Iterator to Camel CaseNavan · PHONE SCREENNavan interview questions
  • Reverse Word Order In PlaceMicrosoft · PHONE SCREENMicrosoft interview questions
  • String CompressionBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions

Interview reports that mention this question

  • Adobe Frontend and QA Interviews: 14 Experiences (Part 6 of 6)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public int compareVersions(String version1, String version2) {
        // Write your code here.
    }
}
Checking account…