given an array of words, how to eliminate the duplicates? You have a simple tree structure Ⓐ and its clone ⓐ. Each node in the tree has a pointer to it's parent as well as an array of its children. Given an original tree's node Ⓑ and cloned tree ⓐ, implement a method that returns ⓑ (the clone of Ⓑ). (Imagine finding the matching UIButton/UISlider/UIView in a separate cloned view controller.) Original Ⓐ ┏━┻━━┓ ◯ ◯ ┏┻┓ ┏━╋━┓ ◯ ◯ ◯ ◯ ◯ ┏┻┓ ┃ ◯ Ⓑ ◯ Clone ⓐ ┏━┻━━┓ ◯ ◯ ┏┻┓ ┏━╋━┓ ◯ ◯ ◯ ◯ ◯ ┏┻┓ ┃ ◯ ⓑ ◯
Anonymous
Since nobody answered regarding the UiView tree question, posting my solution that I finished only after the interview: -(void)originalInput { UIView *B = [UIView someViewWithParentAndChildren]; //known subview UIView *a = [UIView someViewWithParentAndChildren]; //root of clone view tree NSMutableArray *indexPaths = [NSMutableArray new]; [self recordIndexPaths:indexPaths fromView:B]; //creating index array UIView *cloneViewB = [self findViewByIndexes:indexPaths forIndex:0 forView:a]; //recursing through the clone view hierarchy NSLog(@"%@", cloneViewB); } -(void)recordIndexPaths:(NSMutableArray *)indexPaths fromView:(UIView *)view { if (view.parent == nil){ return; }else { UIView *parent = view.parent; int i = [parent.children indexOfObject:view]; [indexPaths insertObject:i atIndex:0]; //i is not and object, but primitive, should be incapsulated in NSNumber in real life!! [self recordIndexPaths:indexPaths fromView:parent]; } } -(UIView *)findViewByIndexes:(NSArray *)indexPaths forIndex:(int)i forView:(UIView *)currentView { if (!currentView.children.count) return currentView; int j = indexPaths[i]; //j is not and object, but primitive, should be incapsulated in NSNumber in real life!! UIView *child = currentView.children[j]; return [self findViewByIndexes:indexPaths forIndex:i+1 forView:child]; }
Check out your Company Bowl for anonymous work chats.