Round 1
Questions:
- 15 questions based on C
- 1 coding question
- 25 questions based on math, cognitive ability, and logical reasoning
The coding question was: You will be given an array which will be multiples of 3 and some array elements will not be a multiple of 3. If it is not a multiple, then either add or subtract a number from it to make it a multiple of 3. You need to return the minimum number of times you add or subtract from a number to make it a multiple of 3.
Test Case 1:
Input: arr = [12, 21, 3, 4]
Output: 1
Explanation: 12, 21, and 3 are all multiples of 3, but 4 is not a multiple. So, subtract 1 from it to make it a multiple of 3. Total operations made was 1 (by subtracting 1 from 4).
Test Case 2:
Input: arr = [4, 5]
Output: 2
int solve(vector<int>& ans) { int n = ans.size(); int sum = 0; for(int i = 0; i < n; i++) { int a = min(3 - ans[i] % 3, ans[i] % 3); sum += a; } return sum; }
Candidate's Approach
The candidate iterated through the array, calculating the minimum number of operations needed to convert each element to a multiple of 3. They used the modulo operation to determine how far each number was from the nearest multiple of 3, either by adding or subtracting.
Interviewer's Feedback
No feedback provided.