<p>You are given an integer array <code>nums</code>.</p>

<p>Return an integer that is the <strong>maximum</strong> distance between the <strong>indices</strong> of two (not necessarily different) prime numbers in <code>nums</code><em>.</em></p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [4,2,9,5,3]</span></p>

<p><strong>Output:</strong> <span class="example-io">3</span></p>

<p><strong>Explanation:</strong> <code>nums[1]</code>, <code>nums[3]</code>, and <code>nums[4]</code> are prime. So the answer is <code>|4 - 1| = 3</code>.</p>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">nums = [4,8,2,8]</span></p>

<p><strong>Output:</strong> <span class="example-io">0</span></p>

<p><strong>Explanation:</strong> <code>nums[2]</code> is prime. Because there is just one prime number, the answer is <code>|2 - 2| = 0</code>.</p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
	<li>The input is generated such that the number of prime numbers in the <code>nums</code> is at least one.</li>
</ul>

class Solution:
    def maximumPrimeDifference(self, nums: List[int]) -> int:
#         @cache
#         def isPrime(n: int) -> bool:
#             if n <= 1:
#                 return False
#             if n <= 3:
#                 return True
#             if n % 2 == 0 or n % 3 == 0:
#                 return False

#             i = 5
#             while i * i <= n:
#                 if n % i == 0 or n % (i + 2) == 0:
#                     return False
#                 i = i + 6

#             return True

#         nums = filter(isPrime, nums)
#         return max(nums or [0]) - min(nums or [0])
        @cache
        def isPrime(n: int) -> bool:
            if n <= 1:
                return False
            if n <= 3:
                return True
            if n % 2 == 0 or n % 3 == 0:
                return False

            i = 5
            while i * i <= n:
                if n % i == 0 or n % (i + 2) == 0:
                    return False
                i = i + 6

            return True

        i, j = 0, len(nums) - 1
        while True:
            if isPrime(nums[i]):
                break
            i += 1
        while j > i:
            if isPrime(nums[j]):
                break
            j -= 1

        return j - i
665