2614. Prime In Diagonal Easy

@problem@discussion
#Array#Math#Matrix#Number Theory



1/**
2 * [2614] Prime In Diagonal
3 *
4 * You are given a 0-indexed two-dimensional integer array nums.
5 * Return the largest prime number that lies on at least one of the diagonals of nums. In case, no prime is present on any of the diagonals, return 0.
6 * Note that:
7 * 
8 * 	An integer is prime if it is greater than 1 and has no positive integer divisors other than 1 and itself.
9 * 	An integer val is on one of the diagonals of nums if there exists an integer i for which nums[i][i] = val or an i for which nums[i][nums.length - i - 1] = val.
10 * 
11 * <img alt="" src="https://assets.leetcode.com/uploads/2023/03/06/screenshot-2023-03-06-at-45648-pm.png" style="width: 181px; height: 121px;" />
12 * In the above diagram, one diagonal is [1,5,9] and another diagonal is [3,5,7].
13 *  
14 * <strong class="example">Example 1:
15 * 
16 * Input: nums = [[1,2,3],[5,6,7],[9,10,11]]
17 * Output: 11
18 * Explanation: The numbers 1, 3, 6, 9, and 11 are the only numbers present on at least one of the diagonals. Since 11 is the largest prime, we return 11.
19 * 
20 * <strong class="example">Example 2:
21 * 
22 * Input: nums = [[1,2,3],[5,17,7],[9,11,10]]
23 * Output: 17
24 * Explanation: The numbers 1, 3, 9, 10, and 17 are all present on at least one of the diagonals. 17 is the largest prime, so we return 17.
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	1 <= nums.length <= 300
30 * 	nums.length == numsi.length
31 * 	1 <= nums<span style="font-size: 10.8333px;">[i][j]</span> <= 4*10^6
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/prime-in-diagonal/
37// discuss: https://leetcode.com/problems/prime-in-diagonal/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn diagonal_prime(nums: Vec<Vec<i32>>) -> i32 {
43        0
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_2614() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.