0
0
LLDsystem_design~10 mins

Board and piece hierarchy in LLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare the base class for all pieces.

LLD
class [1]:
    def __init__(self, color):
        self.color = color
Drag options to blanks, or click blank then click option'
ACell
BBoard
CPiece
DGame
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Board' instead of 'Piece' as the base class name.
2fill in blank
medium

Complete the code to define the board class with a grid attribute.

LLD
class [1]:
    def __init__(self, rows, cols):
        self.grid = [[None for _ in range(cols)] for _ in range(rows)]
Drag options to blanks, or click blank then click option'
ABoard
BPiece
CCell
DGame
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing 'Piece' with 'Board' when naming the class.
3fill in blank
hard

Fix the error in the piece subclass definition for a chess knight.

LLD
class Knight([1]):
    def __init__(self, color):
        super().__init__(color)
Drag options to blanks, or click blank then click option'
ACell
BPiece
CBoard
DGame
Attempts:
3 left
💡 Hint
Common Mistakes
Inheriting from Board or Game instead of Piece.
4fill in blank
hard

Fill both blanks to complete the method that moves a piece on the board.

LLD
def move_piece(self, from_pos, to_pos):
    piece = self.grid[1]from_pos[0]][from_pos[1]]
    self.grid[2]to_pos[0]][to_pos[1]] = piece
Drag options to blanks, or click blank then click option'
A[
B(
C]
D)
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets for list indexing.
5fill in blank
hard

Fill all three blanks to complete the dictionary comprehension that maps piece names to their counts.

LLD
piece_counts = [1]: [2] for [3] in pieces}
Drag options to blanks, or click blank then click option'
Apiece.name
Bpieces.count(piece)
Cpiece
Dpiece.color
Attempts:
3 left
💡 Hint
Common Mistakes
Using piece.color as key instead of piece.name.
Using the wrong variable in the loop.