Given an array of strings arr[], consisting of N strings each representing dot separated numbers in the form of software versions.

Input:_ arr[] = {“1.1.2”, “0.9.1”, “1.1.0”}_

_Output: _“0.9.1” “1.1.0” “1.1.2”

_Input: _arr[] = {“1.2”, “0.8.1”, “1.0”}

_Output: _“0.8.1” “1.0” “1.2”

Recommended: Please try your approach on {IDE} first, before moving on to the solution.

**Approach: **Follow the steps below to solve the problem:

  • Create a function to compare two strings.
  • Store strings into a vector.
  • In order to compare two dot separated strings S1 and S2, iterate up to the length min(S1, S2) + 1 and compare each numerical parts of the string and sort accordingly.
  • Repeat the above steps for each pair of string and sort the array accordingly.
  • Below is the implementation of above idea:

#arrays #mathematical #sorting #strings #google #interview-preparation #java-comparator

Sort an Array of Version Numbers
17.50 GEEK