Leetcode Problem 2644. Find the Maximum Divisibility Score

2644. Find the Maximum Divisibility Score

Leetcode Solutions

Brute Force Approach with Sorting

  1. Sort the divisors array in ascending order.
  2. Initialize max_score to 0 and result to the first element of the sorted divisors array.
  3. Iterate over each divisor in the sorted divisors array. a. Initialize score to 0. b. Iterate over each number in the nums array. i. If the number is divisible by divisor, increment score. c. If score is greater than max_score, update max_score and set result to divisor. d. If score is equal to max_score and divisor is less than result, update result to divisor.
  4. Return result.
UML Thumbnail

Brute Force Approach without Sorting

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...