0
0
LLDsystem_design~10 mins

Search and filter design 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 define the main component responsible for handling search queries.

LLD
class [1]Handler:
    def __init__(self, data_source):
        self.data_source = data_source

    def search(self, query):
        # Implementation to search data_source
        pass
Drag options to blanks, or click blank then click option'
AQuery
BFilter
CSearch
DResult
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic names like 'ResultHandler' which do not clearly indicate search responsibility.
2fill in blank
medium

Complete the code to add a filter method that narrows down results based on a condition.

LLD
class FilterHandler:
    def __init__(self, items):
        self.items = items

    def filter(self, condition):
        return [item for item in self.items if item.[1](condition)]
Drag options to blanks, or click blank then click option'
Afilters
Bmatches
Cequals
Dcontains
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'filters' which is not a valid method on items.
Using 'equals' which checks for exact match, not containment.
3fill in blank
hard

Fix the error in the code to correctly combine search and filter results.

LLD
def search_and_filter(data, query, filter_condition):
    search_results = [item for item in data if query in item]
    filtered_results = [item for item in search_results if item.[1](filter_condition)]
    return filtered_results
Drag options to blanks, or click blank then click option'
Afilter
Bcontains
Cequals
Dmatches
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'filter' which is not a method on string or list items.
Using 'equals' which requires exact match.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps items to their lengths only if length is greater than 3.

LLD
length_map = {item: len(item) for item in items if len(item) [1] 3 and 'a' [2] item}
Drag options to blanks, or click blank then click option'
A>
B<
Cin
Dnot in
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for length comparison.
Using 'not in' instead of 'in' for membership check.
5fill in blank
hard

Fill all three blanks to create a filtered dictionary with uppercase keys and values greater than 10.

LLD
filtered_dict = {item[1]: value for item, value in data.items() if value [2] 10 and item[3]('x')}
Drag options to blanks, or click blank then click option'
A.upper()
B>
Cendswith
Dstartswith
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'endswith' instead of 'startswith' for key filtering.
Using '<' instead of '>' for value comparison.