Pregunta de entrevista de Meta

Find the intersection between 2 NSRanges

Respuestas de entrevistas

Anónimo

4 de nov de 2017

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

Anónimo

10 de jun de 2018

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

Anónimo

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) } }