0
0
LLDsystem_design~10 mins

Immutability for safety 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 an immutable data structure.

LLD
class Config:
    def __init__(self, settings):
        self._settings = [1](settings)

    def get(self, key):
        return key in self._settings
Drag options to blanks, or click blank then click option'
Aset
Bdict
Clist
Dfrozenset
Attempts:
3 left
💡 Hint
Common Mistakes
Using mutable types like dict or list which allow changes.
2fill in blank
medium

Complete the code to ensure thread-safe access to shared data using immutability.

LLD
class SharedData:
    def __init__(self, data):
        self._data = [1](data)

    def read(self):
        return self._data
Drag options to blanks, or click blank then click option'
Aset
Blist
Ctuple
Ddict
Attempts:
3 left
💡 Hint
Common Mistakes
Using mutable types like list or dict which can cause race conditions.
3fill in blank
hard

Fix the error in the code that tries to modify an immutable object.

LLD
config = [1](['read', 'write'])
config.append('execute')
Drag options to blanks, or click blank then click option'
Alist
Btuple
Cset
Dfrozenset
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to append to a tuple or frozenset which causes errors.
4fill in blank
hard

Fill both blanks to create an immutable configuration dictionary.

LLD
from types import [1]

config = [2]({'host': 'localhost', 'port': 8080})
Drag options to blanks, or click blank then click option'
AMappingProxyType
Bdict
CMapping
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using mutable dict instead of a read-only proxy.
5fill in blank
hard

Fill all three blanks to implement a safe update method that returns a new immutable config.

LLD
def update_config(old_config, key, value):
    new_dict = dict(old_config)
    new_dict[[1]] = [2]
    return [3](new_dict)
Drag options to blanks, or click blank then click option'
Akey
Bvalue
CMappingProxyType
Ddict
Attempts:
3 left
💡 Hint
Common Mistakes
Modifying the original config directly or returning a mutable dict.