iOS Interview with Instagram

iOS Interview with Instagram

June 13, 2018




Interview With Instagram

Recently I decided to apply to Instagram for an iOS position, mainly to see how their interview process was and what kinds of questions they asked. This process took about 2 weeks, and there was still more interviews. I wanna write about some of the questions they asked and my approach to them.

First Interview

The first interview was pretty basic information gathering for their company. My experience, current work, projects I felt passionate about, leadership qualities, etc. I found this interview to be very simple and the person I talked to was very friendly and overall it was a great experience

Interview Numero 2

This was the technical interview. This was supposed to be a big one. They had given me materials to look over beforehand that they sent in an email. Along with several videos and other technical questions they had asked before.

First Question

Given any string determine if it is a pallindrome.

My initial approach to this question was to think how would i determine if a string is a pallindrome? Well simple if a string is reversed and then you compare it to the initial string then it is considered a pallindrome. Such as "racecar"


func isPalindrome(string: String) -> Bool {
    return string == String(string.reversed())
}

Easy right, you have to cast string.reversed() to type String because it will return a ReversedCollection< String > which wont work with your comparison. Now initially I thought this would be enough to get started, but I soon realized that that has nothing to do with the question it simply solves if strings are already pallindromes. What you need to find is what makes a pallindrome a pallindrome. Well lets see:

  • A Pallindrome is a string that has at least 2 matching characters
  • A Pallindrome can contain 1 other non matching character.

Alright so lets try and map out each character of the string and add it to a stack and check its count.


func validPalindrome(string: String) -> Bool {
    var characterArray = Set()
    
    string.forEach {
        if !characterArray.contains($0) {
            characterArray.insert($0)
        } else {
            characterArray.remove($0)
        }
    }
    return characterArray.count == 0 || characterArray.count == 1
}

I used a Set of Characters so that I could just insert and remove characters as I went instead of trying to determine the index etc. I then looped through each character in the string and then added it to the characterArray, or removed it if it was already there. I do this because I want to make sure that at the end the count of the character array will either be Zero because we have a string like "TTTT" where all those would be removed and we would be left with a zero count. Or we would have something like "TTATT" where we would have 1 character left.

This answer was accepted