Meta Interview Question

Given two views, write an algorithm to find the closest common super-view if one exists.

Interview Answer

Anonymous

Dec 24, 2020

func getCommonParent(v2: UIView, v2:UIView) -> UIView? { while(v1.parent != null){ let p1 = v1.parent while(v2.parent != null){ let p2 = v2.parent if(p1 == p2) return p1 getCommonParent(p1, p2) } } return nil }