Find the Divisor with Maximum Divisibility Score
IntuitionGiven a list of numbers (nums) and a list of potential divisors (divisors), we want to determine the divisor that divides the most numbers in nums. If
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Given a list of numbers (nums) and a list of potential divisors (divisors), we want to determine the divisor that divides the most numbers in nums. If multiple divisors yield the same divisibility count, we return the smallest divisor.

To achieve this, we iterate through each divisor and check how many numbers in nums it can divide completely (i.e., num % divisor == 0). We maintain a maximum count (mx_cnt) and the corresponding best divisor (ans).
# Approach
<!-- Describe your approach to solving the problem. -->
Initialize ans = -1 and mx_cnt = -1

ans stores the divisor with the highest count of divisible numbers.
mx_cnt tracks the maximum count of numbers a divisor can divide.
Iterate Through Each Divisor (d)

Count how many numbers in nums are divisible by d.
Update the Maximum Count and Answer

If cnt > mx_cnt, update mx_cnt and set ans = d.
If cnt == mx_cnt, update ans to the smaller divisor to ensure lexicographical order.
Return the Answer (ans)

This is the divisor with the highest divisibility score.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
Outer loop: Iterates over divisors, taking O(D) time (where D is the number of divisors).
Inner loop: Iterates over nums, taking O(N) time (where N is the number of elements in nums).
Overall Complexity: O(D × N)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
We use only a few integer variables (O(1) extra space).
No additional data structures are used.
Total Space Complexity: O(1)
# Code
```cpp []
class Solution {
public:
    int maxDivScore(vector<int>& nums, vector<int>& divisors) {
        int ans = -1, mx_cnt = -1;
        // for each divisor
        for (auto d : divisors) {
            int cnt = 0;
            // we check each number `x`
            for (auto x : nums) {
                // to see if `x` can be divisible by `d`
                if (x % d == 0) {
                    // if so, increase the counter by 1
                    cnt += 1;
                }
            }
            // if the counter is greater than the current max
            if (cnt > mx_cnt) {
                // then update hte current max
                mx_cnt = cnt;
                // `d` will be the possible answer
                ans = d;
            } else if (cnt == mx_cnt) {
                // however, if the counter is same as the current max
                // then we need to take the min one
                ans = min(ans, d);
            }
        }
        return ans;
    }
};
```
['Array', 'C++']