Company: Meesho SDE - IIT Kanpur
Difficulty: medium
Spiral Collection Problem Description You are given an n×n matrix and need to traverse it in a spiral pattern starting from a specified position. During the traversal, you collect elements that meet certain mathematical criteria. The spiral moves in a clockwise direction: right, down, left, up, repeating this pattern as you move inward toward the center. Unlike a standard spiral that starts from a corner, this spiral begins at any given position and expands outward layer by layer. You only collect elements whose absolute value is either prime or divisible by 3, and the final result should be sorted in ascending order. Function Description You need to implement the function spiralCollection that performs a clockwise spiral traversal starting from the given position, collects elements based on mathematical criteria, and returns them in sorted order. Function Parameters: n : Integer representing the size of the square matrix. matrix : A 2D vector/array of integers representing the n×n mat