Internet Question Interview Question


Country: United States
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.Arrays;
import java.util.Random;

public class create2DArray {
	
	public static int[][] createArray(int rows, int cols,int a , int b){
		int[][] arr = new int[rows][cols];
		
		Random random = new Random();
		//generate random random between a and b inclusive
		for(int i=0;i<=arr.length-1;i++){
			for(int j=0;j<=arr[0].length-1;j++){
				arr[i][j] = random.nextInt(b-a + 1) + a;
			}
		}
		return arr;
	}
	
	public static boolean checkColumn(int[][] arr,int col, int min , int max){
		System.out.println("MIN MAX :   " + min + " " + max);
		boolean minFlag = false;
		boolean maxFlag = false;
		for(int i=0;i<=arr.length-1;i++){
			if(arr[i][col] == min){
				minFlag=true;
			}
			if(arr[i][col] == max){
				maxFlag=true;
			}
		}
		return minFlag && maxFlag;
	}
	
	public static void main(String[] args) {
		
		int arr[][] = createArray(3,2,25,40);
		int min = Integer.MAX_VALUE;
		int max = Integer.MIN_VALUE;
		
		for(int i=0;i<=arr.length-1;i++){
			for(int j=0;j<=arr[0].length-1;j++){
				System.out.print(arr[i][j]+" ");
				min=Math.min(min, arr[i][j]); // MIN
				max=Math.max(max, arr[i][j]); // MAX
			}
			System.out.println();
		}
		
		System.out.println(checkColumn(arr,0,min,max));	
	}
}

- Mayank Jain August 06, 2017 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More