`{"id":"6087b747-d34b-47ee-9e60-e8ff91072c1d","name":"Saddle Price","description":"1. You are given a square matrix of size 'n'. You are given n*n elements of the square matrix. \r\n2. You are required to find the saddle price of the given matrix and print the saddle price. \r\n3. The saddle price is defined as the least price in the row but the maximum price in the column of the matrix.","inputFormat":"A number n\r\ne11\r\ne12..\r\ne21\r\ne22..\r\n.. n * n number of elements of array a","outputFormat":"Saddle point of the matrix if available or \"Invalid input\" if no saddle point is there.","constraints":"1 &lt;= n &lt;= 10^2\r\n-10^9 &lt;= e11, e12, .. n * m elements &lt;= 10^9","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\nusing namespace std;\n\nvoid saddle_point(int n, vector<vector<int>> &arr)\n{\n // write your code here\n}\n\nint main()\n{\n int n;\n cin >> n;\n vector<vector<int>> arr(n, vector<int>(n));\n for (int i = 0; i < n; i++)\n for (int j = 0; j < n; j++)\n cin >> arr[i][j];\n \n saddle_point(n, arr);\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"python":{"code":"def findSaddlePoint(mat, n):\n \n \n #write your code here\n \n\n\nmatrix = []\nn = int(input());\n\nfor i in range(n): \n a = []\n for j in range(n): \n \n a.append(int(input()))\n matrix.append(a)\n\n# invalid case is handle for you\n\nif (findSaddlePoint(matrix, n) == False):\n print(\"Invalid input\");"}},"points":10,"difficulty":"easy","sampleInput":"4\r\n11\r\n12\r\n13\r\n14\r\n21\r\n22\r\n23\r\n24\r\n31\r\n32\r\n33\r\n34\r\n41\r\n42\r\n43\r\n44","sampleOutput":"41","questionVideo":"https://www.youtube.com/embed/xt0Og8YaON4","hints":[],"associated":[{"id":"2214edbe-2c90-4925-b427-206a9175b8d3","name":"(Saddle Price)What will be the Space Complexity of our solution?","slug":"saddle-price-what-will-be-the-space-complexity-of-our-solution","type":4},{"id":"aaa130a5-c2f1-4ed9-bd4c-198e6dd4bfba","name":"(Saddle Price) What's the first condition to check if a element is a Saddle Price?","slug":"saddle-price-what-s-the-first-condition-to-check-if-a-element-is-a-saddle-price","type":4},{"id":"fb05e73d-6b98-4a11-b237-1b4f05795513","name":"(Saddle Price) What will be the Time complexity of our solution?","slug":"saddle-price-what-will-be-the-time-complexity-of-our-solution","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f185374c-5448-476e-93e8-c4a4e9d1d520","name":"2D Arrays","slug":"2d-arrays-9999","type":0},{"id":"293c3d0b-5966-4b77-89ac-8945fda242b8","name":"Saddle Price","slug":"saddle-price","type":1}],"next":{"id":"49933746-05dd-4fad-950f-b14b28ded5b3","name":"Saddle Price","type":3,"slug":"saddle-price"},"prev":{"id":"36f65bf4-d6d6-492c-9c0a-a837e3ad5698","name":"The State of Wakanda - 2","type":3,"slug":"the-state-of-wakanda-2"}}}`

1. You are given a square matrix of size 'n'. You are given n*n elements of the square matrix. 2. You are required to find the saddle price of the given matrix and print the saddle price. 3. The saddle price is defined as the least price in the row but the maximum price in the column of the matrix.

`{"id":"6087b747-d34b-47ee-9e60-e8ff91072c1d","name":"Saddle Price","description":"1. You are given a square matrix of size 'n'. You are given n*n elements of the square matrix. \r\n2. You are required to find the saddle price of the given matrix and print the saddle price. \r\n3. The saddle price is defined as the least price in the row but the maximum price in the column of the matrix.","inputFormat":"A number n\r\ne11\r\ne12..\r\ne21\r\ne22..\r\n.. n * n number of elements of array a","outputFormat":"Saddle point of the matrix if available or \"Invalid input\" if no saddle point is there.","constraints":"1 &lt;= n &lt;= 10^2\r\n-10^9 &lt;= e11, e12, .. n * m elements &lt;= 10^9","sampleCode":{"cpp":{"code":"#include <iostream>\n#include <vector>\nusing namespace std;\n\nvoid saddle_point(int n, vector<vector<int>> &arr)\n{\n // write your code here\n}\n\nint main()\n{\n int n;\n cin >> n;\n vector<vector<int>> arr(n, vector<int>(n));\n for (int i = 0; i < n; i++)\n for (int j = 0; j < n; j++)\n cin >> arr[i][j];\n \n saddle_point(n, arr);\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"python":{"code":"def findSaddlePoint(mat, n):\n \n \n #write your code here\n \n\n\nmatrix = []\nn = int(input());\n\nfor i in range(n): \n a = []\n for j in range(n): \n \n a.append(int(input()))\n matrix.append(a)\n\n# invalid case is handle for you\n\nif (findSaddlePoint(matrix, n) == False):\n print(\"Invalid input\");"}},"points":10,"difficulty":"easy","sampleInput":"4\r\n11\r\n12\r\n13\r\n14\r\n21\r\n22\r\n23\r\n24\r\n31\r\n32\r\n33\r\n34\r\n41\r\n42\r\n43\r\n44","sampleOutput":"41","questionVideo":"https://www.youtube.com/embed/xt0Og8YaON4","hints":[],"associated":[{"id":"2214edbe-2c90-4925-b427-206a9175b8d3","name":"(Saddle Price)What will be the Space Complexity of our solution?","slug":"saddle-price-what-will-be-the-space-complexity-of-our-solution","type":4},{"id":"aaa130a5-c2f1-4ed9-bd4c-198e6dd4bfba","name":"(Saddle Price) What's the first condition to check if a element is a Saddle Price?","slug":"saddle-price-what-s-the-first-condition-to-check-if-a-element-is-a-saddle-price","type":4},{"id":"fb05e73d-6b98-4a11-b237-1b4f05795513","name":"(Saddle Price) What will be the Time complexity of our solution?","slug":"saddle-price-what-will-be-the-time-complexity-of-our-solution","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f185374c-5448-476e-93e8-c4a4e9d1d520","name":"2D Arrays","slug":"2d-arrays-9999","type":0},{"id":"293c3d0b-5966-4b77-89ac-8945fda242b8","name":"Saddle Price","slug":"saddle-price","type":1}],"next":{"id":"49933746-05dd-4fad-950f-b14b28ded5b3","name":"Saddle Price","type":3,"slug":"saddle-price"},"prev":{"id":"36f65bf4-d6d6-492c-9c0a-a837e3ad5698","name":"The State of Wakanda - 2","type":3,"slug":"the-state-of-wakanda-2"}}}` Editor

easy

1. You are given a square matrix of size 'n'. You are given n*n elements of the square matrix. 2. You are required to find the saddle price of the given matrix and print the saddle price. 3. The saddle price is defined as the least price in the row but the maximum price in the column of the matrix.

## Constraints

1 <= n <= 10^2 -10^9 <= e11, e12, .. n * m elements <= 10^9

## Format

### Input

A number n e11 e12.. e21 e22.. .. n * n number of elements of array a

### Output

Saddle point of the matrix if available or "Invalid input" if no saddle point is there.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}4 11 12 13 14 21 22 23 24 31 32 33 34 41 42 43 44```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}41`

Question Video

Discussions

Show Discussion

Related Resources 