Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Improving a Custom View Assignment
00:00
5 left

Improving a Custom View Assignment

MediumPython

Problem

How would you update this custom view to make it better?

Implement a function that identifies which custom view items require redrawing after a state update. Each item has a unique ID and rendering properties: position, size, and color. Return changed, added, and removed IDs in deterministic order.

Input: two lists of item dictionaries. Output: a list of dirty IDs, with updated items first and removed items afterward.

Constraints

  • 0 <= len(old_items), len(new_items) <= 1000
  • Each item is a dictionary with keys id, x, y, width, height, and color
  • IDs are unique within each list
  • Rendering properties are integers except color, which is a string
  • Return updated or added IDs in new_items order, followed by removed IDs in old_items order

Function Signature

def dirty_view_items(old_items, new_items):
Interviewer

Your question is Improving a Custom View Assignment. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.