Practice Most Frequent Prime
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Most Frequent Prime
Problem Statement
Given the digit matrix mat, start at every cell and follow each possible straight direction: north, northeast, east, southeast, south, southwest, west, or northwest. Append each visited digit to the number being formed, and count a number at every step along the path. A path cannot turn or leave the matrix. Among the generated prime numbers greater than 10, return the most frequent one; break frequency ties by choosing the larger prime. Return -1 if none exists.
Source: Most Frequent Prime on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
mat = [[1,1],[9,9],[1,1]]
19
# Example 2
mat = [[7]]
-1
# Example 3
mat = [[9,7,8],[4,6,5],[2,8,6]]
97
Constraints
Related LeetCode Problems
Practice more problems similar to Most Frequent Prime.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.