In this post we can see complete solution for the HackerRank Exercise Subarray Division. The problem statement goes like this - Determine how many ways can divide the chocolate bar (as contiguous segment) between Lily and Ron given condition : The length of the segment matches Ron's birth month The sum of the integers on the squares is equal to his birth day. Read complete challenge detail from HackerRank Working solution in Swift given below: func birthday ( s : [ Int ] , d : Int , m : Int ) -> Int { var sCount = 0 var index = 0 // 1 while ( index < s. count ) { var dayLength = 0 let limit = index +m > s. count ? s. count : index +m // 2 for jIndex in index ..< limit { dayLength += s [ jIndex ] } // 3 if dayLength == d { sCount += 1 } ...
Mobile App Developer | Technopreneur