We’re preparing your current view and syncing the latest data.
Given an array of integers, find the maximum difference between two elements such that both elements are prime numbers. Return -1 if there are less than two prime numbers in the array.
An integer array nums is given as input.
Return an integer representing the maximum difference between two prime numbers in the array. If fewer than two prime numbers exist, return -1.
1 <= nums.length <= 10^5 1 <= nums[i] <= 10^6
Example 1
Input
[2, 3, 5, 7, 11, 13]
Output
11
Explanation
The maximum difference is between 13 and 2, which is 11.
Example 2
Input
[4, 6, 8, 10]
Output
-1
Explanation
There are no prime numbers in the array, so return -1.