View hierarchy tree search
You're given a specific UIView instance in an original view hierarchy, plus a copy of that hierarchy with the same structure. How would you design a function that finds the corresponding view in the copy?
You're given a specific UIView instance in an original view hierarchy, plus a copy of that hierarchy with the same structure. How would you design a function that finds the corresponding view in the copy?
Record the path from the root to the target (the subviews index at each level) and follow the same indexes down the copy, which is O(depth); without the path, walk both trees in lockstep and return the copy's node at the moment the original's node is the target. Differing structure and view reuse are the edge cases.
UIKitShort answerBasics
How would you write a function that starts at a root view and finds a view matching some…
#bfs #dfs #view-hierarchy
CS fundamentals and algorithmsShort answerAdvanced
An image mask comes as an N×M grid where 1 is foreground and 0 is background. How would…
#bfs #dfs
CS fundamentals and algorithmsShort answerAdvanced
You're recursively walking a nested JSON document thousands of levels deep, and it…
#recursion
CS fundamentals and algorithmsShort answerBasics
A home decor recommender follows a graph of room-to-room connections to find the minimum…
#bfs