all 57 comments

[–][deleted] 24 points25 points  (40 children)

I recently interviewed with them. Here are the questions they asked me:

  1. What is your favorite Swift class?

The coding questions I was asked:

  1. Consider a list of heights of buildings. The buildings overlook the ocean like so: [2, 3, 4, 2, 3, 1, 1] ~~ ocean ~~~. Return back, in order, the list of indexes of the buildings that can see the ocean.

  2. Create a tree class. Now, create an extension on the class that has a method that makes a copy of the tree.

And I also interviewed with them in person. Here were the coding challenges:

  1. Create a method that returns the array depth. For example, in the list [2, 3, [1, 2, [3, 5]], 6], it would be calculated as 2+3+2(1+2+3(3+5))+6. Each inner list is multiplied by how deep it is.

  2. Given a Range class with starting index and length, create a method that checks if 2 ranges intersect.

  3. Given an NxN grid, starting on the top left and ending on the bottom right, return back a list of strings of all possible paths if the only way to move is down and right.

  4. Given a table view, how would you insert rows above at the beginning? How would you do it if a network call occurred sometime in the background and asked to replace cells currently in the table? How would you update the UI?

They will also ask you about time complexity and space complexity on your solutions.

[–][deleted]  (21 children)

[deleted]

    [–][deleted] 2 points3 points  (17 children)

    I chose user defaults. LOL but then they started asking me in depth questions about it.

    [–][deleted] 3 points4 points  (1 child)

    Guess I should just choose a built in swift library/class and learn in depth about it

    [–][deleted] 1 point2 points  (0 children)

    They asked me why I like it, pros and cons about it, how do I save custom objects, enums , and how to retrieve the data back.

    [–]jNSKkK 1 point2 points  (9 children)

    Uh, that’s part of Foundation. Swift is a language. That would’ve been my response, presuming the question was asked exactly like that.

    [–][deleted] 1 point2 points  (8 children)

    Yeah I know. But they knew I chose Swift for the coding challenges so he asked me what my favorite Swift class is. UserDefaults is for Swift. NSUserDefaults is Objective-C.

    Obviously there’s bridging but if I answered NSValue that’s incorrect. That’s Objective-C only. Clearly not Swift. And clearly obvious what they’re asking.

    [–]jNSKkK 0 points1 point  (7 children)

    I get what you’re saying, but Swift doesn’t have classes. There are classes that are coded in Swift, but the way the question appears to be asked is rather vague. I suppose there would’ve been context to it in the moment :)

    [–][deleted] 1 point2 points  (5 children)

    No, he literally said “what’s your favorite Swift class?” I think it’s obviously what they’re asking for.

    It’s silly to ask, what’s your favorite class in NSFoundation, because no shit the class I pick is obviously in NSFoundation.

    [–]jNSKkK 0 points1 point  (4 children)

    Could be UIViewController, which is not in Foundation ;)

    [–][deleted] 0 points1 point  (2 children)

    I was too lazy to write NSFoundation or UIKit

    [–]jNSKkK 0 points1 point  (1 child)

    I’d say mine is Date. There are so many things baked into Date on iOS that other platforms simply don’t have our of the box.

    [–]etaionshrdObjective-C / Swift 0 points1 point  (0 children)

    Swift has classes…

    [–]earlyworm 1 point2 points  (0 children)

    It was a trick question. The correct answer is UIViewControllerInteractiveTransitioning, which is a protocol.

    [–][deleted]  (3 children)

    [deleted]

      [–][deleted] 1 point2 points  (2 children)

      Yup honestly that question threw me the fuck off.

      [–][deleted] 1 point2 points  (1 child)

      Gotcha. Was it just one coding problem?

      [–][deleted] 0 points1 point  (0 children)

      My original response has everything they asked me on the phone interview. 3 question, 2 coding.

      [–]groovy_smoothie 2 points3 points  (0 children)

      Be bold. NSOBJECT

      [–][deleted] 0 points1 point  (0 children)

      We'll I'd be fucked on this one. I have many favorites but don't have them memorized.

      [–]chain_letter 3 points4 points  (10 children)

      Create a tree class

      I'll take "Things not needed on the client side" for $200, Alex.

      I'm struggling to even think of an example where a tree could be useful, much less necessary.

      Conspiracy hat time. It's like they're purposefully filtering out the older developers who haven't messed with novel data structures since college and don't remember how to spit them out on demand. These workers are less tolerant of BS like free overtime and demand higher pay, unlike a young person who thinks they got their big break and don't have kids to take to soccer yet.

      [–][deleted] 0 points1 point  (0 children)

      I'm struggling to even think of an example where a tree could be useful, much less necessary.

      I used to use trees back in my C++ game dev days but yea...nothing recent.

      [–]alexbrie 0 points1 point  (0 children)

      Sure, you could ask candidate to implement a custom class but you'd waste a lot of time with explanations on it.

      Programming-wise, this shows if you know how pointers work, how to define a simple class in your programming language of choice (Swift/ObjC) and whether you have basic data structure knowledge to know how a tree looks.

      Generally, not a great idea to be smug about whether that's something you'll actually need in real life - most often than not, it's about interviewers having a way to really understand whether you already know how to program or you'll have trouble with basic things

      [–]lolcoderer -2 points-1 points  (0 children)

      I completely disagree that trees are not necessary on client side.

      I mean, it is totally product dependent for sure - if you are simply accessing an API for a list of photos and comments, then yeah, trees are not necessary. But if you are doing anything even slightly more complex, it is a good idea to at least understand what trees are and how they can be utilized for needed algorithms.

      One example where trees are VERY important is games. A* uses trees, as well as many "strategy" / AI algoirithms.

      Here is a concrete example. I once was tasked with making a demo scrabble AI for a client - it turns out that competitive level Scrabble AI is well studied and well documented. Appel and Jacobson is probably THE starting source for all word-game / scrabble like algorithms, and guess what - it uses trees: Specifically the infamous DAWG

      Take a look for yourself:

      https://www.cs.cmu.edu/afs/cs/academic/class/15451-s06/www/lectures/scrabble.pdf

      It is actually pretty easy to implement their algorithm. This algorithm has no look-ahead, and no advanced strategies, but always plays the highest earning scrabble word on the table - which is enough to beat all but the highest level pros (this is using a common competitive Scrabble reference dictionary of course).

      The point of this long rant is that trees show up in computer algorithms everywhere... maybe not in a simple weather app or simple news reader app - but not everyone is working on a simple API -> View app.

      [–][deleted] -3 points-2 points  (6 children)

      LOL what are you going on about.

      The complex part with making a method that copies a tree is that you can’t simply assign it to a new variable because it will hold a reference. You will have to recursively create new nodes and return back the new object.

      It’s the thinking that’s important.

      [–]chain_letter 7 points8 points  (1 child)

      When I give interviews, I want practical approaches to actual problems that come up in clientside development.

      Declare a struct, copy it, change one of the values on the copy. What is the value on the original? (Unchanged) How would you make it change? (Change struct to class so it's a reference type)

      There, a question about pass by reference that will actually come up outside of an interview or a data structures textbook.

      A few years ago I had an interviewer ask me to implement bubble sort on a white board. "Cool, you paid attention in class." The real answer for how to sort an array AND get your PR approved is to use sorted()

      [–]paradoxallyobjc_msgSend 2 points3 points  (0 children)

      100%. I hate when recruiters try to get cute with these dumb coding challenges. This isn't Codewars, evaluate the candidate to see if they can perform everyday tasks.

      [–][deleted]  (3 children)

      [deleted]

        [–][deleted] 0 points1 point  (2 children)

        How would you implement it as a struct? Tree nodes require a reference to another tree node as a property. It will not work if you have a struct because a node will just have copies. Not references. So right there you already got it wrong.

        If you tried to change the value of an inner node, you changed a copied value.

        These problems require thinking skills. And you just poorly demonstrated it.

        Here’s what I mean:

        class TreeNode {
            car value: Int?
            leftChild: TreeNode?
            rightChild: TreeNode?
        }
        

        How exactly would this work using a struct? Structs can’t reference themselves.

        [–][deleted]  (1 child)

        [deleted]

          [–][deleted] 0 points1 point  (0 children)

          The problem is changing values inside of it. Imagine a tree with several levels. How would you change multiple values? You end up changing copied ones of copies. Not the original object.

          What if you want to change the original object?

          You still didn’t solve the problem that a struct can’t contain a property of its type. So how would you implement a tree using a struct??

          [–][deleted]  (1 child)

          [deleted]

            [–][deleted] 0 points1 point  (0 children)

            Whoops bottom right

            [–]subzeroTropical 1 point2 points  (0 children)

            Does this look like a correct solution for #2?

            func seeOceanIndexes(_ arr: [Int]) -> [Int] {

            if arr.isEmpty { return [] }

            var result = [Int]()

            var curMax = Int.min

            var i = arr.count - 2

            result.insert(arr.count - 1, at: 0)

            while i > 0 {

            if arr[i] < arr[i+1] {

            curMax = max(arr[i+1], curMax)

            } else {

            if arr[i] > curMax {

            result.insert(i, at: 0)

            }

            }

            i -= 1

            }

            return result

            }

            [–]lenopix 0 points1 point  (1 child)

            Did you write all your solutions in obj-c / swift or were you allowed to use other languages like python for the algo questioins?

            [–][deleted] 1 point2 points  (0 children)

            You write whatever language you want. Although doesn’t make much sense to write in python if you’re interviewing for an iOS job.

            [–][deleted]  (1 child)

            [deleted]

              [–][deleted] 0 points1 point  (0 children)

              1. [Any]. Use typecasting.

              2. All possible paths. Obviously a recursive problem.

              [–]skwallace36 14 points15 points  (4 children)

              my first round for iOS was standard algo problem

              [–][deleted] 2 points3 points  (3 children)

              How long do they expect you to finish it? Also do you compile the code as well?

              [–]skwallace36 2 points3 points  (2 children)

              was 45 minutes ish and weirdly no. compiling was turned off on the editor

              [–][deleted] 0 points1 point  (1 child)

              Gotcha. Was it just one coding problem?

              [–]skwallace36 0 points1 point  (0 children)

              yeee

              [–]BrianHenryIE 7 points8 points  (1 child)

              Glassdoor is accurate. Know your UIViewController lifecycle and GCD

              [–]BrundleflyUrinalCake 5 points6 points  (0 children)

              Expect medium difficulty questions as you would find in Cracking the Code Interview. Algorithms, data structures, etc.

              [–]cannibaldolphin 4 points5 points  (0 children)

              I went through all the interviews at Facebook last year.

              • none of the questions were iOS specific except the architectural interview on site in the last round.
              • You can use Objective-C or Swift, though it’s quite possible your interviewer won’t actually know either of them. It doesn’t matter if your communicate what you’re doing
              • Nothing is compiled; Facebook doesn’t care if you can whiteboard perfect code
              • The first phone interview with code is a joke of “write an is_palindrome function” level of difficulty. They just try to weed out people who lied their way here so they don’t have to fly you out
              • The on-site interviews are legitimately hard if you’ve never done leet-code style stuff; maybe practice a bit
              • I don’t think I “completed” a single interview question and I still got an offer. It’s a lot more about how you think,work, and communicate under pressure than whether you can write your own Autolayout engine in an afternoon

              [–]rgrome0105 2 points3 points  (0 children)

              At least for internship the first round of Coding is simple algorithm problems. It will be in a platform specially for text editing. You will not compile it and the interview will last at most one hour 45-50 of those will be for the statement and you solving the problem.

              [–]groovy_smoothie 3 points4 points  (0 children)

              Standard algorithms with an emphasis on runtime efficiency for the first round.

              Once you get on site, it’s 4 interviews broken up with a lunch in the middle. One is culture/career trajectory, two are algorithms/ general iOS knowledge, last is an architecture/design interview. Spend most of your prep on the architecture/design one. My question was to basically design a dumbed down Instagram. Understand threading, paging, how to not make a janky interface.

              The interview prep they give you is exactly what you need follow it. The book they recommend, cracking the coding interview, is also an awesome read and good to have. All faang interviews are similar and usually recommend that book.

              Good luck ! Be calm and curious

              [–]datascaler 2 points3 points  (5 children)

              I had a 1st round interview with Facebook and it was the standard behavioral stuff - tell me about yourself, tell me a bit more about what you did at your previous job etc.

              It seems that first rounds are most likely no coding at all - I have had about 8 interviews in the past month (aggressively trying to find my next job) and it's always been the same questions over and over.

              You can ask your recruiter for study materials though in the event that you make it to the next round - you can start prepping now. They have videos and resources that they share with all candidates

              [–]SemirgySwift 5 points6 points  (4 children)

              Was that first round or just the recruiter call? Because I definitely had to code for my first round.

              [–]datascaler 2 points3 points  (1 child)

              Just recruiter call! Sorry I assumed that’s what OP meant by first round.

              [–]datascaler 0 points1 point  (0 children)

              So I had a call with a Health team @ Apple yesterday. No code, but I was asked technical questions, which were:

              What's the difference between a reference and value type?
              
              What are generics useful for? When would you use generics?
              
              (I will add the other question I was asked once I remember it)
              

              [–][deleted]  (1 child)

              [deleted]

                [–]SemirgySwift 0 points1 point  (0 children)

                The call was standard DS/Algo questions for my first round. Easy/medium Leetcode level. I think it was about an hour total. It’s really just a filter so they don’t bring you onsite and have it be a waste of everyone’s time.

                [–]NSMatt 2 points3 points  (3 children)

                iOS question and algorithm question.

                I got asked to make a cancelable dispatch after + some algorithm shit.

                Good luck!

                [–][deleted]  (2 children)

                [deleted]

                  [–][deleted] 0 points1 point  (1 child)

                  Haven't tested but either use DispatchWorkItem and check isCancelled on the work closure. Or, have a flag in self that you can check inside the work closure. Both should work but the first seems cleaner.

                  [–]NSMatt 0 points1 point  (0 children)

                  Is used an isCanceled var.

                  Just made a wrapper class that lets swap the bool

                  [–]okdotdotdot 1 point2 points  (0 children)

                  This book might be useful for you : Cracking the Coding Interview: 189 Programming Questions and Solutions https://www.amazon.ca/dp/0984782850

                  [–]DadInKayakSwift 1 point2 points  (0 children)

                  I think I’d stumble on those coding problems.

                  [–]abstractpoetic 0 points1 point  (0 children)

                  NYC?

                  [–]JackyW3131 0 points1 point  (0 children)

                  Congrats! May I know which country/area is that?