Count Winning Dice Face Pairs
Updated
Problem statement
Two custom dice have face values listed in dieA and dieB. Count the pairs of face occurrences (i, j) for which dieA[i] > dieB[j].
Repeated face values are separate occurrences. Equal values do not count as wins. For this exercise, the dice may have different numbers of faces and values may be negative. Return the exact count as a 64-bit integer.
Interview follow-up
If both input arrays are already sorted, solve the count in linear time.
Function
countWinningDicePairs(dieA: int[], dieB: int[]) → longExamples
Example 1
dieA = [2,2,4]dieB = [1,2,3]return = 5Each occurrence of 2 beats the 1, contributing two wins. The 4 beats all three B faces, contributing three more.
Example 2
dieA = [-1,0]dieB = [-2,-1,1]return = 3The -1 face beats only -2. The 0 face beats -2 and -1. Equality does not win.
Constraints
- 1 <= dieA.length, dieB.length <= 10^5
- -10^9 <= dieA[i], dieB[j] <= 10^9
More Google Phone Screen questions
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
- Minimum Total Layover WaitPHONE SCREEN · Seen Nov 2026
- Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Count Centaur Friend RequestsMeta · PHONE SCREENMeta interview questions
- Count Triples That Can Form a TriangleAdobe · PHONE SCREENAdobe interview questions
- 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
- 3SumAmazon · PHONE SCREEN
- Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
- Find All Pythagorean TripletsDell Technologies · PHONE SCREENDell Technologies interview questions
- Meeting Rooms IIUber · PHONE SCREENUber interview questions
- Sort a Quadratic-Transformed ArrayLinkedIn · PHONE SCREENLinkedIn interview questions
- Find K Closest Elements in a Sorted ArrayNavi · PHONE SCREEN
- Sort ColorsVisa · PHONE SCREENVisa interview questions