First Bad Version Problem Statement

You are the product manager leading the development of a new product. Unfortunately, one of the product versions failed the quality check, causing all subsequent versions to be bad. Given array of versions numbered [1, 2, ..., n], your task is to identify the first bad version.

An API function isBadVersion(version) is available and determines whether a given version is bad. Your function must find the first bad version while minimizing the number of calls to the API.

Explanation:

Given two version strings Version1 and Version2 representing version numbers, your task is to compare them and determine which one is the latest version.

Input:

 The first line contains an integer 'T' denoting the number of test cases. Each test case consists of: 
The first line: a string 'Version1'.
The second line: a string 'Version2'.

Output:

For each test case, output 
1 if Version1 is the latest,
-1 if Version2 is the latest, and
0 if both versions are the same.
Output the result for each test case on separate lines.

Example:

Input: 
Version1 = "1.23.45", Version2 = "1.23.456"
Output:
-1
Explanation:

First two parts of both strings are same. Third part of Version2 is greater than that of Version1, thus Version2 is of the latest version.

Constraints:

  • 1 ≤ T ≤ 100
  • 1 ≤ |Version1| ≤ 10000
  • 1 ≤ |Version2| ≤ 10000
  • Time limit: 1 second

Note:

No need for printing in implementation. Handle only the logic.

Be the first one to answer
Add answer anonymously...
Microsoft Corporation Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter