Kth Element In Matrix

easy
1. You are given an matrix with NxN elements. 2. You are also given a number K. 3. You have to find the Kth smallest element in the matrix. 4. For example, consider the following 2D array. 10, 20, 30, 40 15, 25, 35, 45 24, 29, 37, 48 32, 33, 39, 50 The 3rd smallest element is 20 and 7th smallest element is 30. 5. display is a utility function, feel free to use it for debugging purposes. 6. main takes input from the users and creates the matrix. 7. This is a functional problem. 8. You have to complete the findKthSmallest function. It takes as input a matrix and K. It should return the Kth smallest element in the matrix. 9. Don't change the code of main and display.

Input Format

First line takes input N, the size of the square matrix. Next N lines take input N space separated numbers representing the elements of the matrix. Last line takes input K. Input is handled for you.

Output Format

Kth smallest element in the matrix. Output is handled for you.

Constraints

1 <= N <= 100

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
4
10 20 30 40
15 25 35 45
24 29 37 48
32 33 39 50
7
Output
30
Previous
Heap Sort
Next
Kth Largest Element In An Array

Related Questions