Maximum Prime Difference

You are given an integer array nums.

Return an integer that is the maximum distance between the indices of two (not necessarily different) prime numbers in nums.

Example 1
Inputnums = [4,2,9,5,3]
Output3
nums[1], nums[3], and nums[4] are prime, so the answer is |4 - 1| = 3.
Example 2
Inputnums = [4,8,2,8]
Output0
nums[2] is prime, and because there is just one prime number, the answer is |2 - 2| = 0.

Constraints

  • 1 <= nums.length <= 3 * 10^5
  • 1 <= nums[i] <= 100
  • The input is generated such that the number of prime numbers in the nums is at least one.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate