The Diamond Problem in Multiple Inheritance

Hard Advanced Inheritance & MRO
Solve in Playground →

Problem Statement

Set up a diamond hierarchy: `A`, `B(A)`, `C(A)`, `D(B, C)`. Define a `ping(self)` method in each that first calls `super().ping()` (except in A), and then prints its own class name (‘A’, ‘B’, ‘C’, ‘D’). Instantiate `D` and call `ping()` to see the order of resolution.

Input Format

None

Output Format

Print the class names in the resolved execution order.

Constraints

None

Sample Output

A
C
B
D

Explanation

Because super() dynamically follows the MRO, the initialization propagates all the way up to A, then prints on the way back down the call stack in reverse MRO: A, C, B, D.

Starter Code

class A:
    def ping(self):
        print('A')

class B(A):
    # Call super().ping() then print 'B'
    pass

class C(A):
    # Call super().ping() then print 'C'
    pass

class D(B, C):
    # Call super().ping() then print 'D'
    pass

if __name__ == '__main__':
    d = D()
    d.ping()

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used