Google L4 Onsite Interview Question
- Posted
- 7 Jun 2025
Summary
This post describes a specific coding question encountered during a Google L4 onsite interview, emphasizing the importance of clarifying assumptions about input properties.
How it went
You are given two N-sided dice, P and Q, where each die has N integer values (not necessarily unique or standard).
When rolled, each side is equally likely to appear.
Given the values on each side of dice P and Q, determine:
The number of outcomes where P's roll is greater than Q's roll (i.e., P wins).
Follow up 1: The number of outcomes where Q wins.
Follow up 2: The number of outcomes where both rolls are equal (tie).
Example: (N=3)
P = [1, 2, 4] Q = [2, 2, 5]
Edit 1: Forgot to add that P and Q are always in non-decreasing sorted order. ^ This information was not provided, I had to ask clarifying questions to get it. So if you start coding without asking this, you probably end up with a non-optimal solution.
Questions asked (1)
- 01
Dice Roll Outcomes (P Wins, Q Wins, Tie)
Data Structures & Algorithms · Medium
You are given two N-sided dice, P and Q, where each die has N integer values (not necessarily unique or standard).
When rolled, each side is equally likely to appear.
Given the values on each side of dice P and Q, determine:
The number of outcomes where P's roll is greater than Q's roll (i.e., P wins).
Follow up 1: The number of outcomes where Q wins.
Follow up 2: The number of outcomes where both rolls are equal (tie).
Example: (N=3)
P = [1, 2, 4] Q = [2, 2, 5]
Edit 1: Forgot to add that P and Q are always in non-decreasing sorted order. ^ This information was not provided, I had to ask clarifying questions to get it. So if you start coding without asking this, you probably end up with a non-optimal solution.