google logo
Google· SDE II

Google L4 Onsite Interview Question

Posted
7 Jun 2025
342 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.

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)

  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.

Know someone preparing? Send it to them:WhatsAppLinkedInX

Interviewed at Google recently?

Write up your rounds while you still remember the questions. It helps the next person more than you would think.

Share your experience
Discussion 0

Questions for the author, or how your own interview compared.

Join the discussion

Sign in with Google to comment or ask the author a question.

No comments yet

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