Intel Interview Experience (On-Campus) 2023
Last Updated :
06 Sep, 2023
In the spring of 2023, I had the privilege of interviewing for a position at Intel on my college campus. The interview process was not only challenging but also provided an exciting opportunity to showcase my problem-solving skills using Java. In this article, I will recount my experience and share how I tackled two specific 2D array problems posed by the interviewers.
Problem 1: Counting 1s and 0s
The interview began with the classic “introduce yourself” question. After a brief introduction, the interviewer wasted no time delving into the technical questions. They asked me to open a notepad and presented the first problem:
Problem Statement: Given a 2D array containing only 1s and 0s, write a Java function to find the number of 1s and 0s in the array.
Solution:
I started by writing a Java function that iterated through the entire 2D array, keeping count of the number of 1s and 0s encountered. The code snippet looked something like this:
int countOnes = 0;
int countZeros = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
if (matrix[i][j] == 1) {
countOnes++;
} else if (matrix[i][j] == 0) {
countZeros++;
}
}
}
System.out.println(“Number of 1s: ” + countOnes);
System.out.println(“Number of 0s: ” + countZeros);
Problem 2: Replacing 0s with 1s
Once I had successfully tackled the first problem, the interviewer presented the second challenge:
Problem Statement: Given the same 2D array, write a Java function to replace all the 0s in a row with 1s if that row contains at least one 1.
Solution:
For this problem, I wrote a Java function that iterated through each row of the 2D array, checking if there was at least one occurrence of 1. If a row contained a 1, I replaced all the 0s in that row with 1s. Here’s a simplified version of the code:
for (int i = 0; i < rows; i++) {
boolean containsOne = false;
for (int j = 0; j < columns; j++) {
if (matrix[i][j] == 1) {
containsOne = true;
break;
}
}
if (containsOne) {
for (int j = 0; j < columns; j++) {
if (matrix[i][j] == 0) {
matrix[i][j] = 1;
}
}
}
}
Bonus Question: Finding the Second Largest Element
As a final challenge, the interviewer posed a bonus question: “Find the second largest element in the 2D array without sorting it.”
Solution:
To solve this problem, I implemented a Java function that iterated through the array while keeping track of the largest and second largest elements encountered. Here’s the code:
int largest = Integer.MIN_VALUE;
int secondLargest = Integer.MIN_VALUE;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
if (matrix[i][j] > largest) {
secondLargest = largest;
largest = matrix[i][j];
} else if (matrix[i][j] > secondLargest && matrix[i][j] != largest) {
secondLargest = matrix[i][j];
}
}
}
System.out.println(“Second Largest Element: ” + secondLargest);
Conclusion:
My Intel campus interview experience in 2023 was both challenging and rewarding. It allowed me to showcase my Java programming skills and problem-solving abilities. By confidently addressing the given 2D array problems and the bonus question, I left the interview room with a sense of accomplishment and hope for a promising future at Intel.
Share your thoughts in the comments
Please Login to comment...