Problem · Array

Determine Dice Outcomes (For L4 :)

EasyFULLTIMEONSITE INTERVIEW

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).
  • P and Q are always in non-decreasing sorted order.

    Examples
    01 · Example 1
    P = [1, 2, 4]
    Q = [2, 2, 5]
    return = [-0, -0, -0]
    Hello - Example output is just a placeholder to let the system not complain about missing output :)
    drafts saved locally
    public int[] determineDiceOutcomes(int[] P, int[] Q) {
      // write your code here
    }
    
    P[1, 2, 4]
    Q[2, 2, 5]
    expected[-0, -0, -0]
    sign in to submit