For this Question: Given an n x n matrix and a number x, find whether given element present in matrix or not, every row and column is sorted in increasing order. The designed algorithm should have linear time complexity.first line contain two element n and x.
next n line contain n space separated integer i. e. element of matrix.

Constraints:
1<=n,x<=1000print "Yes" is given element is present in matrix otherwise print "No".Sample Input 1:
3 5
1 2 3
2 4 5
3 6 9
Sample Output 1:
Yes

Explanation :
5 present in given matrix at 2nd row and third column., I have written this Solution Code: import java.util.*;
class Main {
	private static void search(int[][] mat,
									int n, int x)
	{
		int i = 0, j = n - 1;
		while (i < n && j >= 0)
		{
			if (mat[i][j] == x)
			{
				System.out.print("Yes");
				return;
			}
			if (mat[i][j] > x)
				j--;
			else
				i++;
		}

		System.out.print("No\n");
		return; 
	}
	// driver program to test ab
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int n,x;
        n=sc.nextInt();
		x=sc.nextInt();
		int [][]arr=new int[n][n];

		for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
        arr[i][j]=sc.nextInt();

		search(arr, n, x);
	}
}
// This code is contributed by Arnav Kr. Mandal, In this Programming Language: Java, Now tell me if this Code is compilable or not?