Google L4 Onsite Interview Question

google logo
google
SDE II
June 7, 20254 reads

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)

Q1
Dice Roll Outcomes (P Wins, Q Wins, Tie)
Data Structures & AlgorithmsMedium

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.

Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!