0
0
LLDsystem_design~20 mins

Piece movement rules (polymorphism) in LLD - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Polymorphism Mastery in Piece Movement
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding polymorphism in piece movement

In a chess game design, each piece moves differently. How does polymorphism help in implementing movement rules?

AIt uses static methods to define movement rules that cannot be overridden.
BIt forces all pieces to share the same movement logic, reducing code duplication.
CIt stores all movement rules in a single global function that all pieces call.
DIt allows each piece class to define its own move method, enabling different movement behaviors through a common interface.
Attempts:
2 left
💡 Hint

Think about how different pieces can have unique move logic but still be treated as the same type.

Architecture
intermediate
2:00remaining
Designing piece movement with polymorphism

You are designing a chess game. Which class design best uses polymorphism for piece movement?

AUse a global function that takes piece type and position to calculate moves, without classes.
BCreate a Piece class with a single move() method that uses if-else to check piece type and apply movement.
CCreate a base Piece class with an abstract move() method. Each piece subclass implements move() with its own logic.
DDefine movement rules in a configuration file and parse them at runtime without polymorphism.
Attempts:
2 left
💡 Hint

Consider how polymorphism avoids complex conditionals and supports extensibility.

scaling
advanced
2:30remaining
Scaling piece movement rules for new game variants

You want to add new chess variants with additional pieces and movement rules. How does polymorphism help scale your design?

ABy allowing new piece classes to inherit from the base Piece class and override move(), new rules integrate seamlessly.
BBy modifying the base Piece class move() method to include all new movement rules for every variant.
CBy storing all movement rules in a single monolithic function that checks piece type and variant.
DBy duplicating the entire codebase for each variant to handle different movement rules.
Attempts:
2 left
💡 Hint

Think about how inheritance and overriding support adding new behaviors without changing existing code.

tradeoff
advanced
2:30remaining
Tradeoffs of polymorphism vs conditional logic in piece movement

What is a key tradeoff when using polymorphism for piece movement rules compared to using conditional statements inside a single method?

APolymorphism reduces the number of classes but makes adding new pieces harder.
BPolymorphism improves code clarity and extensibility but may increase the number of classes and complexity.
CUsing conditionals is more extensible and easier to maintain than polymorphism.
DPolymorphism always results in slower performance than conditionals.
Attempts:
2 left
💡 Hint

Consider maintainability and class count when choosing design approaches.

component
expert
3:00remaining
Request flow for validating piece movement using polymorphism

In a chess game system, describe the flow of a move request using polymorphism to validate if a piece can move to a target square.

AClient sends move request → Game controller calls piece.move(target) → Piece subclass validates move → Returns valid/invalid → Controller updates board.
BClient sends move request → Game controller checks piece type → Calls global validateMove(piece, target) function → Updates board.
CClient sends move request → Game controller uses a switch-case on piece type to call specific validation functions → Updates board.
DClient sends move request → Board directly updates piece position without validation → Game controller logs move.
Attempts:
2 left
💡 Hint

Focus on how polymorphism lets the controller treat all pieces uniformly.