3115. Maximum Prime Difference Medium

@problem@discussion
#Array#Math#Number Theory



1/**
2 * [3115] Maximum Prime Difference
3 *
4 * You are given an integer array nums.
5 * Return an integer that is the maximum distance between the indices of two (not necessarily different) prime numbers in nums.
6 *  
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">nums = [4,2,9,5,3]</span>
10 * Output: <span class="example-io">3</span>
11 * Explanation: nums[1], nums[3], and nums[4] are prime. So the answer is |4 - 1| = 3.
12 * </div>
13 * <strong class="example">Example 2:
14 * <div class="example-block">
15 * Input: <span class="example-io">nums = [4,8,2,8]</span>
16 * Output: <span class="example-io">0</span>
17 * Explanation: nums[2] is prime. Because there is just one prime number, the answer is |2 - 2| = 0.
18 * </div>
19 *  
20 * Constraints:
21 * 
22 * 	1 <= nums.length <= 3 * 10^5
23 * 	1 <= nums[i] <= 100
24 * 	The input is generated such that the number of prime numbers in the nums is at least one.
25 * 
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/maximum-prime-difference/
30// discuss: https://leetcode.com/problems/maximum-prime-difference/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35    pub fn maximum_prime_difference(nums: Vec<i32>) -> i32 {
36        0
37    }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_3115() {
48    }
49}
50


Back
© 2025 bowen.ge All Rights Reserved.