I am trying to generate a function find_indices(int num) in java which when called with a certain parameter would check the presence of that parameter in a 2D array say K,and would return its indices (indices in the matrix K).
I am talking about something similar like this:
int min=(int)Math.min(K[i][j],K[j][i]);
find_indices(min);
//
find_indices(int num)
{
//Now this method will return the indices of num in the 2D array K(if present)
}
Okay there are two things i have no idea about:
- When i call a function that is supposed to return me two variables(i & j),how do i catch/hold/store them when they are returned?
- I need an efficient way to search for num in the matrix K[][]. Since the number of testcases would be high,and on top of that if i use two for loops(O(n^2)searching technique) for each of such test cases, i guess i would run into a TLE. Hence i need to know the good ways to optimize searching process in a 2D array.
Any kind of help/suggestions regarding the above problems would be extremely helpful. Thank you.