FPEvalDataset/LeetCodeProblem
0304
1{2 "id": 3314,3 "name": "most_frequent_prime",4 "difficulty": "Medium",5 "link": "https://leetcode.com/problems/most-frequent-prime/",6 "date": "2024-02-11 00:00:00",7 "task_description": "You are given a `m x n` **0-indexed **2D** **matrix `mat`. From every cell, you can create numbers in the following way: There could be at most `8` paths from the cells namely: east, south-east, south, south-west, west, north-west, north, and north-east. Select a path from them and append digits in this path to the number being formed by traveling in this direction. Note that numbers are generated at every step, for example, if the digits along the path are `1, 9, 1`, then there will be three numbers generated along the way: `1, 19, 191`. Return _the most frequent prime number **greater** than _`10`_ out of all the numbers created by traversing the matrix or _`-1`_ if no such prime number exists. If there are multiple prime numbers with the highest frequency, then return the largest among them._ **Note:** It is invalid to change the direction during the move. **Example 1:** ** ** ``` ** Input:** mat = [[1,1],[9,9],[1,1]] **Output:** 19 **Explanation:** From cell (0,0) there are 3 possible directions and the numbers greater than 10 which can be created in those directions are: East: [11], South-East: [19], South: [19,191]. Numbers greater than 10 created from the cell (0,1) in all possible directions are: [19,191,19,11]. Numbers greater than 10 created from the cell (1,0) in all possible directions are: [99,91,91,91,91]. Numbers greater than 10 created from the cell (1,1) in all possible directions are: [91,91,99,91,91]. Numbers greater than 10 created from the cell (2,0) in all possible directions are: [11,19,191,19]. Numbers greater than 10 created from the cell (2,1) in all possible directions are: [11,19,19,191]. The most frequent prime number among all the created numbers is 19. ``` **Example 2:** ``` **Input:** mat = [[7]] **Output:** -1 **Explanation:** The only number which can be formed is 7. It is a prime number however it is not greater than 10, so return -1. ``` **Example 3:** ``` **Input:** mat = [[9,7,8],[4,6,5],[2,8,6]] **Output:** 97 **Explanation:** Numbers greater than 10 created from the cell (0,0) in all possible directions are: [97,978,96,966,94,942]. Numbers greater than 10 created from the cell (0,1) in all possible directions are: [78,75,76,768,74,79]. Numbers greater than 10 created from the cell (0,2) in all possible directions are: [85,856,86,862,87,879]. Numbers greater than 10 created from the cell (1,0) in all possible directions are: [46,465,48,42,49,47]. Numbers greater than 10 created from the cell (1,1) in all possible directions are: [65,66,68,62,64,69,67,68]. Numbers greater than 10 created from the cell (1,2) in all possible directions are: [56,58,56,564,57,58]. Numbers greater than 10 created from the cell (2,0) in all possible directions are: [28,286,24,249,26,268]. Numbers greater than 10 created from the cell (2,1) in all possible directions are: [86,82,84,86,867,85]. Numbers greater than 10 created from the cell (2,2) in all possible directions are: [68,682,66,669,65,658]. The most frequent prime number among all the created numbers is 97. ``` **Constraints:** `m == mat.length` `n == mat[i].length` `1 <= m, n <= 6` `1 <= mat[i][j] <= 9`",8 "public_test_cases": [9 {10 "label": "Example 1",11 "input": "mat = [[1,1],[9,9],[1,1]]",12 "output": "19 "13 },14 {15 "label": "Example 2",16 "input": "mat = [[7]]",17 "output": "-1 "18 },19 {20 "label": "Example 3",21 "input": "mat = [[9,7,8],[4,6,5],[2,8,6]]",22 "output": "97 "23 }24 ],25 "private_test_cases": [26 {27 "input": [28 [29 8,30 731 ],32 [33 6,34 735 ]36 ],37 "output": 6738 },39 {40 "input": [41 [42 6,43 3,44 645 ],46 [47 9,48 4,49 250 ],51 [52 7,53 2,54 355 ]56 ],57 "output": 2358 },59 {60 "input": [61 [62 763 ],64 [65 266 ]67 ],68 "output": -169 },70 {71 "input": [72 [73 7,74 9,75 676 ],77 [78 6,79 8,80 481 ],82 [83 8,84 4,85 486 ],87 [88 9,89 1,90 191 ],92 [93 4,94 2,95 896 ],97 [98 9,99 2,100 9101 ]102 ],103 "output": 41104 },105 {106 "input": [107 [108 4,109 6,110 5111 ],112 [113 7,114 4,115 1116 ],117 [118 4,119 1,120 5121 ],122 [123 8,124 3,125 1126 ],127 [128 2,129 5,130 1131 ],132 [133 4,134 5,135 9136 ]137 ],138 "output": 11139 }140 ],141 "haskell_template": "mostFrequentPrime :: [[Int]] -> Int\nmostFrequentPrime mat ",142 "ocaml_template": "let mostFrequentPrime (mat: int list list) : int = ",143 "scala_template": "def mostFrequentPrime(mat: List[List[Int]]): Int = { \n \n}",144 "java_template": "class Solution {\n public int mostFrequentPrime(int[][] mat) {\n \n }\n}",145 "python_template": "class Solution(object):\n def mostFrequentPrime(self, mat):\n \"\"\"\n :type mat: List[List[int]]\n :rtype: int\n \"\"\"\n "146}