Bird
0
0
LLDsystem_design~10 mins

Extensibility (NxN board, multiple players) 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 initialize the board size for an NxN game.

LLD
class Board:
    def __init__(self, size):
        self.size = [1]
        self.grid = [[None for _ in range(size)] for _ in range(size)]
Drag options to blanks, or click blank then click option'
A10
Bsize
Cboard_size
Dn
Attempts:
3 left
💡 Hint
Common Mistakes
Using a hardcoded number instead of the parameter.
Using an undefined variable.
2fill in blank
medium

Complete the code to add a player to the game.

LLD
class Game:
    def __init__(self):
        self.players = []

    def add_player(self, player):
        self.players.[1](player)
Drag options to blanks, or click blank then click option'
Aappend
Badd
Cinsert
Dextend
Attempts:
3 left
💡 Hint
Common Mistakes
Using add which is for sets, not lists.
Using extend which expects an iterable.
3fill in blank
hard

Fix the error in the method that checks if a move is valid on the NxN board.

LLD
def is_valid_move(self, x, y):
    if x < 0 or x >= self.size or y < 0 or y >= [1]:
        return False
    return self.grid[x][y] is None
Drag options to blanks, or click blank then click option'
Aself.size
Bself.length
Cself.board_size
Dself.dimension
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined attributes like self.length or self.dimension.
4fill in blank
hard

Fill both blanks to implement a method that returns the current player's turn index and increments it for multiple players.

LLD
def next_turn(self):
    current = self.current_player_index
    self.current_player_index = (self.current_player_index [1] 1) [2] len(self.players)
    return current
Drag options to blanks, or click blank then click option'
A+
B-
C%
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction instead of addition.
Using floor division instead of modulo.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each player to their score if the score is greater than zero.

LLD
scores = { [1]: [2] for [1] in self.players if self.scores[[1]] [3] 0 }
Drag options to blanks, or click blank then click option'
Aplayer
Bself.scores[player]
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for key and loop variable.
Using < instead of > for filtering.