Google L4 TPS | Onsite ML round advice
Anonymous User
1062
Apr 04, 2025
Apr 04, 2025
Role: SWE III L4 AI/ML
Cleared technical phone screen round.
Question & solution:
/*
Say we have a game of dice, where a single dice can have N sides,
each with equal probability to come up when the dice is thrown.
There are two dice A and B, and they both have N sides.
The dice may have non-standard values on their sides, including duplicates.
The question is, given the values of the sides of the two dice,
across all possible ways for the dice to fall, in how many ways does A win?
A dice wins when its number is greater than the other dice number.
For example, say the dice are 3-sided, with the values: A = [2, 2, 4], B = [1, 2, 3].
If A comes up 2, and B comes up 1, A wins.
If A comes up 2 and B comes up 2, it's a tie.
If A comes up 2 and B comes up 3, B wins.
The number of ways for A to win is 5 {A: 2, B: 1}, {A: 2, B: 1}, {A: 4, B: 1}, {A: 4, B: 2}, {A: 4, B: 3}.
*/
public class Solution {
public long waysAWinsSorted(int[] diceA, int[] diceB){
long count = 0;
for (int a : diceA){
// we want to count how many sides in B are stricly less than a.
// use binary search that returns the index of the first element greater than eq. to a.
int idx = firstIndexGreaterOrEqual(diceB, a);
count += idx;
}
return count;
}
// returns the index of the first element in a sorted array >= target
private int firstIndexFeaterOrEqual(int [] arr, int target){
int low = 0, high = arr.length;
while(low < high){
int mid = low + (high - low) / 2;
if(arr[mid] >= target){
high = mid;
}
else {
low = mid + 1;
}
}
return low;
}
}
}
// time complexity: O(n log n)
// Optimized to O(n) using two pointer approach given both arrays are sorted
public static long waysAWinsTwoPointer(int[] diceA, int[] diceB) {
int pointerB = 0;
long wins = 0;
int lenB = diceB.length;
// For each outcome in dice A, count how many outcomes in dice B are strictly less.
// Because both arrays are sorted, pointerB only moves forward.
for (int a : diceA) {
while (pointerB < lenB && diceB[pointerB] < a) {
pointerB++;
}
wins += pointerB;
}
return wins;
}
Now I'll have 3 technical virtual onsite round coming up, 2 coding and 1 ML.
- Please give advice for ML round.
- Will there be a ML coding question related to a NLP/CV/ML-problem statement?
- What all topics should I expect in the ML round interview?
- Will there be questions from my resume?
Not able to find much relevant posts / advice for ML round.
Comments (7)


