# Find distinct versions in a list of versions with wildcards included

 Category: Data Structure And Algorithms Tags:

Hi,

I came across a requirement in my office where we have versions in format like 1.1, 2.0.0.0, 1.*, 3.4.* etc. here 1.* includes all the version from 1.0-1.99 similarly 3.4.* includes all the versions from 3.4.0-3.4.99. We can have maximum of 4 parts in version.
Now I have given a list of versions and I have to write a function which returns distinct versions from list. Suppose the list is given to me is:

1.*

1.1.7

2.2

2.2

2.2

2.2.2

2.3.*

3.1

3.1.*

3.5.2

7.0.0.0
And output should be:

1.*        -> 1.* and 1.1.7 are included in 1.*

2.2       -> 2.2 and 2.2 are duplicates so added only one entry

2.2.2    -> 2.2.2 is only distinct version

2.3.*     -> 2.3.* is only distinct version

3.1.*     -> 3.1.* and 3.1 is included in 3.1.*

3.5.2    -> 3.5.2 is only distinct version

7.0.0.0 -> 7.0.0.0 is only distinct version

 Like 0 People
 Nikhil Joshi Ceo & Founder at Dotnetlovers Atricles: 164 Questions: 16 Given Best Solutions: 16 *

I have found the answer myself, I have used divide method to split the problem and solved it. Let's see how I solved this. Look at two versions below:

In above picture we can see two versions 1.1.* and 1.1, we know 1.1 is part of 1.1.* since first two parts of versions are same and the third one is * in one of them so distinct version out of above two is 1.1.* . Now similarly any version like 1.1.3.4, 1.1.2.4, 1.1.3 all would come under 1.1.* . In above picture we have columns 0,1,2 which are indexes of version parts. We will follow same in our logic.

Like 1 Person on 12 April 2020