Problem Statement in English

You’re given two version numbers, version1 and version2, and you need to compare them.

Versions are separated by dots (’.’), and each part is an integer. The comparison should be done based on the integer values of each part, ignoring leading zeros.

If one part has fewer versions, the missing parts are considered to be 0.

You should return:

  • 1 if version1 > version2
  • -1 if version1 < version2
  • 0 if version1 == version2

Approach

This is a straightforward implementation problem.


Solution in Python


class Solution:
    def maxFrequencyElements(self, nums: List[int]) -> int:
        c = Counter(nums)
        l = sorted(c.values(), reverse=True)

        target = l[0]
        res = 0

        for x in l:
            if x == target:
                res += target
            else:
                break

        return res

Complexity

  • Time: O(nlogn)O(n \log n), where nn is the length of the input list nums. This is due to the sorting step.

  • Space: O(n)O(n), where nn is the number of unique elements in nums. This is due to the space used by the counter and the sorted list.


And we are done.