Google L4 Onsite Interview Question
Summary
This post describes a specific coding question encountered during a Google L4 onsite interview, emphasizing the importance of clarifying assumptions about input properties.
Full Experience
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.
Interview Questions (1)
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.