Skip to main content

Posts

Showing posts from October, 2021

HackerRank Exercise: Subarray Division solved in Swift 5

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

HackerRank Exercise: Apple and Orange solved in Swift

 In this post we can solve exercise problem "Apple and Orange" in which we should print the number of apples and oranges that land on Sam's house.  Read complete challenge detail from  hackerrank.com Full Swift Solution is given below: func countApplesAndOranges ( s : Int , t : Int , a : Int , b : Int , apples : [ Int ] , oranges : [ Int ]) -> Void { // 1 let applesDistance = apples. map ( { $ 0 + a }) var totalAppleOk = 0 applesDistance. forEach ({ ad in // 2 if ( s .. . t ) . contains ( ad ) { totalAppleOk = totalAppleOk + 1 } }) print ( " \( totalAppleOk ) " ) // prints number of Apples let orangeDistance = oranges. map ( { $ 0 + b }) var totalOrangeOk = 0 orangeDistance. forEach ({ od in if ( s .. . t ) . contains ( od ) { totalOrangeOk = totalOrangeOk ...

Hackerrank Exercise : Utopian Tree solved in Swift

In this post, we have Swift 5.0 solution for Hackerrank exercise - Utopian Tree . We have find out the height of  Utopian Tree, which goes through 2 cycles of growth every year. Each spring, it doubles in height. Each summer, its height increases by 1 meter. Full details of exercise link  hackerrank.com/challenges/utopian-tree/problem Here is the working solution:           func   utopianTree ( n :   Int )   ->   Int   {          var   height   =   0          for   cycle   in   0 .. . n   {              height   =   ( cycle   -   1 )   %   2   ==   0   ?   height   *   2   :   height   +   1            }  ...

Safari Technology Preview | Best way to debug WebPages in iPhone, iPad or Mac Apps.

I enjoyed using Web Inspector tool from Safari Developer options to debug active web pages in iPhone or iPad. For instance, WKWebView running on iPhone. With the update of MacOS Big Sur 11.4 it got broke !! The Safari (14.1.1) web inspector only limited to Sources, Console and Audit. Also this issue started floating in SO thread here . Last week I got rescued by a lesser known application (at lest in my team!) Safari Technology Preview from Apple. Safari Technology Preview app will give you full scale options includes the most recent version of WebKit, the rendering engine that powers Safari. It requires a Mac running macOS Mojave v10.14 or later. I highly recommend this Apple provided in-house Browser for Developer.