You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the previous version, all the versions after a bad version are also bad. Suppose you have n versions [1, 2, ..., n] and you want to find out the first bad one, which causes all the following ones to be bad. You are given an API bool isBadVersion(version) which returns whether version is bad. Implement a function to find the first bad version. You should minimize the number of calls to the API.

You are given two strings ‘Version1’ and ‘Version2’ representing the version numbers. Your task is to compare them and find out which one of them is the latest version.

Note:
The input strings consist of digits and dots only and both the strings are started and terminated by a digit. There are no leading zeros and no zeros following a dot in both the strings except in the case of zero itself.
For Example:
Version1 = “1.23.45”, Version2 = “1.23.456”

The first two parts of both the strings are the same. The third part of Version2 is greater than the third part of Version1, thus string Version2 is of the latest version.
Input format:
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then, the T test cases follow.

The first line of each test case contains the string ‘Version1’.

The second line of each test case contains the string ‘Version2’.
Output format:
For each test case, print 1 if version 1 is latest, -1  if version 2 is latest and 0 if both versions are the same.

Print output of each test case in separate lines.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 100
1 <= |Version1| <= 10000 
1 <= |Version2| <= 10000

Time limit: 1 second
CodingNinjas
author
2y

1. Applied binary search on the data
2. Returned first matching item

CodingNinjas
author
2y
Using Recursion

The idea is to use a recursive approach to compare the versions. Here we will start iterating through both the strings to extract the number till we reach a dot (or the end of the strin...read more

CodingNinjas
author
2y
Using Iteration

The idea is to use an iterative approach to compare both strings. The approach is similar to the previous approach just that we will be doing it in an iterative manner.

We will use fou...read more

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
Get AmbitionBox app

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