Predict the Diamond MRO

Hard ⏱ 18 min 28% acceptance ★★★★★ 4.6
Given the diamond class A, class B(A), class C(A), class D(B, C) where each defines who() returning its letter except B (which doesn't define it) — write the classes and a function resolve() returning D().who(). Python's C3 linearization checks D → B → C → A; since B lacks who(), C's wins. Return that answer and be ready to explain D.__mro__.

Examples

Example 1
Input
resolve()
Output
'C'
Explanation

MRO order D, B, C, A — the first class providing who() is C.

Constraints

  • B must NOT define who().
  • Use the exact inheritance shape.

Topics

OOPMROmultiple inheritance

Companies

GoogleMicrosoftBloomberg

Hints

Hint 1

Print D.__mro__ while experimenting.

Hint 2

Method lookup walks the MRO left to right.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.