Find the Maximum Divisibility Score — LeetCode 2644 Python Solution
EasyArray
- Problem
- #2644
- Reading time
- 2 min
- Source
- leetcode.com
The problem
You are given two integer arrays nums and divisors. The divisibility score of divisors[i] is the number of indices j such that nums[j] is divisible by divisors[i].
Python solution
Python
class Solution:
def maxDivScore(self, nums: List[int], divisors: List[int]) -> int:
ans, mx = divisors[0], 0
for div in divisors:
cnt = sum(x % div == 0 for x in nums)
if mx < cnt:
mx, ans = cnt, div
elif mx == cnt and ans > div:
ans = div
return ansComplexity
| Measure | Complexity |
|---|---|
| Time | O(m \times n), where m and n are the lengths of nums and divisors respectively |
| Space | O(1) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 2644. Find the Maximum Divisibility Score?
- LeetCode 2644. Find the Maximum Divisibility Score is rated Easy on LeetCode.
- What is the time complexity of LeetCode 2644. Find the Maximum Divisibility Score?
- The Python solution on this page runs in O(m \times n), where m and n are the lengths of nums and divisors respectively.
- What is the space complexity of LeetCode 2644. Find the Maximum Divisibility Score?
- The Python solution on this page uses O(1) auxiliary space.
- What topics does LeetCode 2644. Find the Maximum Divisibility Score cover?
- LeetCode 2644. Find the Maximum Divisibility Score is tagged Array on LeetCode.