# Category: Interviews

## Questions to ask when joining a new company as an iOS engineer

What timezone will you be working in? Are all team members working in the same timezone? This is especially important; otherwise, you may end up working a 24-hour shift. Imagine if the person responsible for making code design decisions sits in another timezone or country; you will end up wasting a lot of time waiting

## Implement Merge Intervals in Swift

Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input. Example 1: Input: intervals = [[1,3],[2,6],[8,10],[15,18]] Output: [[1,6],[8,10],[15,18]] Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6]. Example 2: Input: intervals = [[1,4],[4,5]] Output: [[1,5]] Explanation: Intervals [1,4]

## Find the largest number by swapping adjacent digits if they have the same parity in Swift

Problem description: You are given a number. You can swap two adjacent digits, if they are both odd or even. For e.g. given (3,8), you can’t swap them. But you can swap (5,9) since they are both odd. They have the same parity. A similar problem is explained here https://www.youtube.com/watch?v=qEIGhVtZ-sg Function description: swapDigitsAndGetLargestNumber(number: String) Returns:

## Given string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.

The explanation is here https://www.youtube.com/watch?v=3QJzHqNAEXs We use a stack here to store the values. If the previous number is greater than the current number, we will remove the previous number. Else store the number in the stack.

## 1372. Longest ZigZag Path in a Binary Tree

You are given the root of a binary tree. A ZigZag path for a binary tree is defined as follow: Choose any node in the binary tree and a direction (right or left). If the current direction is right, move to the right child of the current node; otherwise, move to the left child. Change the direction from right

## Word ladder implementation in Swift

https://leetcode.com/problems/word-ladder/ This post contains the implementation for the leetcode problem shown in the link above. A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> … -> sk such that: Every adjacent pair of words differs by a single letter. Every si for 1 <= i <= k is in wordList. Note that beginWord does not need to be in wordList.

## Permutations of a string in Swift

Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. Example 1: Input: nums = [1,2,3] Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] Example 2: Input: nums = [0,1] Output: [[0,1],[1,0]] Example 3: Input: nums =  Output: [] Constraints: 1 <= nums.length <= 6 -10 <= nums[i] <= 10 All the integers of nums are unique.

## Magical Candy Bags

Magical Candy BagsYou have N bags of candy. The ith bag contains arr[i] pieces of candy, and each of the bags is magical!It takes you 1 minute to eat all of the pieces of candy in a bag (irrespective of how many pieces of candy are inside), and as soon as you finish, the bag

## Element Swapping

Given a sequence of n integers arr, determine the lexicographically smallest sequence which may be obtained from it after performing at most k element swaps, each involving a pair of consecutive elements in the sequence. Note: A list x is lexicographically smaller than a different equal-length list y if and only if, for the earliest

## Struct vs Class in Swift

If you look at structs and classes in Swift, they seem similar, but the most fundamental difference between them is how they handle values passed to them. In general Struct is pass by value, whereas Class is pass by reference. I will explain the difference by showing an example. In the above code, I have

## Fisher Yates In Place shuffle implementation

In swift you could also use var arr = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] arr.shuffle() Both will give you similar performance when you measure it using XCTest. Here is a chart to prove it.

## Find minimum in a rotated sorted array

View the code on Gist.

## Fizzbuzz implementation in Swift

View the code on Gist.

## 76. Minimum Window Substring in Swift

Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string “”. The testcases will be generated such that the answer is unique. A substring is a contiguous sequence of characters within the string. Example 1: Input: s = “ADOBECODEBANC”, t = “ABC”

## Find Median from Data Stream

The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value and the median is the mean of the two middle values. For example, for arr = [2,3,4], the median is 3. For example, for arr = [2,3], the median is (2 + 3) / 2 = 2.5.

## Largest Triple Products in Swift

Largest Triple Products You’re given a list of n integers arr[0..(n-1)]. You must compute a list output[0..(n-1)] such that, for each index i (between 0 and n-1, inclusive), output[i] is equal to the product of the three largest elements out of arr[0..i] (or equal to -1 if i < 2, as arr[0..i] then includes fewer

## Print level order tree in Objective C (with the help of queues)

View the code on Gist. View the code on Gist.

## Recursively printing out all subviews within a view

View the code on Gist.