0
0
LLDsystem_design~20 mins

Composite pattern in LLD - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Composite Pattern Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding the Composite Pattern Structure
In the Composite pattern, which component is responsible for defining the interface for all objects in the composition, including both simple and complex elements?
ALeaf component
BComposite component
CComponent interface
DClient component
Attempts:
2 left
💡 Hint
Think about which part defines the common operations for all objects.
Architecture
intermediate
2:00remaining
Composite Pattern Request Flow
Consider a file system modeled using the Composite pattern where folders are composites and files are leaves. When a client calls the 'getSize()' method on a folder, what is the correct flow of requests?
AThe folder sums sizes by calling getSize() on each child, which may be files or folders recursively.
BThe folder returns a fixed size without checking children.
CThe folder calls getSize() only on files directly inside it, ignoring subfolders.
DThe folder delegates getSize() calls to the client to handle.
Attempts:
2 left
💡 Hint
Think about how composite objects handle operations on their children.
scaling
advanced
2:30remaining
Scaling Composite Pattern for Large Hierarchies
When using the Composite pattern to model a large organizational chart with thousands of employees and departments, which approach best improves performance when calculating total salaries?
ACache the total salary at each composite node and update caches on changes.
BRecalculate total salary from scratch on every request.
CUse a separate flat list of employees and ignore the composite structure.
DLimit the depth of the hierarchy to reduce recursion.
Attempts:
2 left
💡 Hint
Think about avoiding repeated expensive calculations.
tradeoff
advanced
2:00remaining
Tradeoffs in Composite Pattern Design
What is a common tradeoff when using the Composite pattern to unify individual objects and compositions in a system?
AIt eliminates the need for interfaces but complicates inheritance.
BIt improves performance but increases memory usage drastically.
CIt reduces code reuse but makes debugging easier.
DIt simplifies client code but can make the design more complex and harder to restrict types.
Attempts:
2 left
💡 Hint
Consider how uniformity affects design flexibility and complexity.
component
expert
3:00remaining
Identifying Component Responsibilities in Composite Pattern
In a GUI framework using the Composite pattern, which component should handle the 'draw()' operation to correctly render both simple widgets and containers with children?
AOnly the Composite components implement draw(), leaves do not implement draw().
BLeaf components implement draw() to render themselves; Composite components implement draw() by calling draw() on children.
CThe client calls draw() directly on each leaf, skipping composites.
DA separate renderer class handles draw() for all components.
Attempts:
2 left
💡 Hint
Think about how each component type contributes to rendering.