Pergunta de entrevista da empresa Meta

Find the intersection between 2 NSRanges

Respostas da entrevista

Sigiloso

4 de nov. de 2017

Did you manage to finish the question. How many questions did he gave you ?

Sigiloso

10 de jun. de 2018

func findIntersection(range1: NSRange, range2: NSRange) -> NSRange { let intersection = NSIntersectionRange(range1, range2) return intersection }

Sigiloso

13 de abr. de 2020

extension NSRange { func my_intersection(with range: NSRange) -> NSRange? { guard range.lowerBound <= self.upperBound || self.lowerBound <= range.upperBound else { return nil } let start = max(self.lowerBound, range.lowerBound) let end = min(self.upperBound, range.upperBound) return NSRange(location: start, length: end - start) } }