Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

04 Matrix -> 04 Find nth element of spiral matrix #21

Open
FazeelUsmani opened this issue Dec 17, 2020 · 0 comments
Open

04 Matrix -> 04 Find nth element of spiral matrix #21

FazeelUsmani opened this issue Dec 17, 2020 · 0 comments

Comments

@FazeelUsmani
Copy link
Owner

FazeelUsmani commented Dec 17, 2020

  1. Find nth element of spiral matrix

Easy Accuracy: 35.1% Submissions: 4824 Points: 2
Given a matrix with n rows and m columns. Your task is to find the kth element which is obtained while traversing the matrix spirally. You need to complete the method findK which takes four arguments the first argument is the matrix A and the next two arguments will be n and m denoting the size of the matrix A and then the forth argument is an integer k denoting the kth element . The function will return the kth element obtained while traversing the matrix spirally.

Example 1:

Input:
n = 3, m = 3, k = 4
A[][] = [[1 2 3],
[4 5 6],
[7 8 9]]
Output: 6
Explanation: The matrix above will look
like
1 2 3
4 5 6
7 8 9
and the 4th element in spiral fashion
will be 6 .
Your Task:
You only need to implement the given function findK(). Do not read input, instead use the arguments given in the function. Return the K'th element obtained by traversing matrix spirally.

Expected Time Complexity: O(NM)
Expected Auxiliary Space: O(N
M)

Constraints:
1<=n,m<=20
1<=k<=n*m

@FazeelUsmani FazeelUsmani self-assigned this Dec 17, 2020
@FazeelUsmani FazeelUsmani changed the title 4 04 Matrix -> 04 Find nth element of spiral matrix Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant