I came across a requirement in my office where we have versions in format like 1.1, 220.127.116.11, 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:
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
18.104.22.168 -> 22.214.171.124 is only distinct version
Thanks in advance.
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 126.96.36.199, 188.8.131.52, 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.