Python one-liner for beginners!
Solution:\n\n\ndef maxDivScore(self, nums: List[int], divisors: List[int]) -> int:\n    return max( divisors, key=lambda div: (sum( [num%div==0 for num in nums]
# Solution:\n\n```\ndef maxDivScore(self, nums: List[int], divisors: List[int]) -> int:\n    return max( divisors, key=lambda div: (sum( [num%div==0 for num in nums] ), -div) )\n```\n\nNot a difficult problem so we can afford brute force.\nI go through every divisor. For each divisor, I go through every nums and check how many of them it can divide. I make sure to return the smallest divisor in case of a tie.\nSince this is an easy problem, I will explain the one-liner in a beginner friendly-way below. Enjoy!\n**The keywords that you might want to check if you\'re a python beginner are bolded**\n\n# Detailed explanation\n\nI simply want the maximum of all divisors. The trick is, I don\'t want the maximum in the sense of the largest one, I want the one that maximizes a certain function (namely, a function that would tell me how many nums it can divide)\n\n\nWell, rejoice, that\'s why we\'re using python! The **built-in max function** in python lets you specify the `key` to use for the comparison of the elements as a function. \n\nOur `key` is going to be the number of nums that a divisor can divide (which you can check with `num%div==0`), so the function could be something simple like that:\n```\ndef key(divisor):\n  count=0\n  for num in nums:\n    if num%divisor==0:\n      count+=1  \n  return count\n```\n\nHere, we\'re taking the challenge of writing it all in one line, so let\'s try to compress this function into one line first. We could make use of **list comprehensions**. Something like this: `[num%divisor==0 for num in nums]`. That gives you a boolean array with ones when divisor can divide the num at this index, and 0 when it can not. How do we count how many success we got? Well, we can just sum it all to count the ones! So our one-line function is:\n```\ndef key(divisor):\n  return sum([num%divisor==0 for num in nums])\n```\n\nHm, that\'s 2 lines tho. We can use the power of **lambda functions** to compress it into one-line:\n```\nkey = lambda divisor: sum([num%divisor==0 for num in nums])\n```\n\nThere\'s just one more tricky thing to handle: In case of equality, we want to return the smallest divisor... Luckily, python is really convenient, and it lets us do that. If we use a key function that returns several values, it will use the second element as a tie-breaker when the first ones are equal! our tie-breaker should be `-divisor`, so that `max` will return the smallest value:\n```\nkey = lambda divisor: ( sum([num%divisor==0 for num in nums]), -divisor)\n```\n\nCongrats, all that\'s left to do is to is to put it in the max function and that\'s your return value\n\n```\nmax( divisors, key=lambda div: (sum( [num%div==0 for num in nums] ), -div) )\n```\n\nHopefully, the explanation makes the one-liner easy to digest for everybody!\n\n\n# Complexity\ntime: O(m*n), space: O(n)
['Python3']