Swift

Swift Exercise

Everyone knows that everyone else hates LeetCode, and so companies tend to be coy whenever they give you some kind of algorithmic problem by giving you a "LeetCode-Lite". The only difference between this and “classic” LeetCode is, usually, these rounds will avoid the bullsh*tty questions you have to just know like graph traversal or tree recursion. Usually, you’re given some data, and asked to manipulate, parse, or process it in some way. Seriously, both of my LeetCode-lite exercises had this format: I was given a list of events like timestamps or purchases, and needed to compute some aggregate value for a specific date or date range. In the sample project, we get a stream of data points with customers, spend, and date strings: ``` [ PurchaseEvent(customerId: "C1", date: "2024-01-01", amount: 20.0), PurchaseEvent(customerId: "C2", date: "2024-01-01", amount: 30.0), PurchaseEvent(customerId: "C1", date: "2024-01-01", amount: 20.0), PurchaseEvent(customerId: "C2", date: "2024-01-02", amount: 40.0), PurchaseEvent(customerId: "C3", date: "2024-01-02", amount: 60.0) ] ``` The challenge is to aggregate the data, and write a function to compute the average revenue per customer on a specific date. LeetCode practice comes in very handy here, because you’ll often be pressed on the O(n) time and space complexity of your solution. Historically, I’ve passed several interviews where I gave suboptimal solutions, as long as I was able to talk through or pseudo-code out the optimal version when pressed. Hashmaps are your friend, usually. The most effective way to get comfortable at answering these kinds of random data processing questions by doing LeetCode questions anyway. A lot of the time, you might just get a relatively easy LeetCode-style question, because teams are scared to put off everyone who didn’t bother grinding LeetCode yet. * Write a function that gets the nth Fibonacci number * Evaluate whether a string of parentheses { [ < [ has evenly-matched opens and closes. * Calculate a maths function using reverse polish notation * Count the prime numbers that exist less than a value n * You might literally be given a FizzBuzz variant One final thought: Advent of Code might be the collection of questions that matches this format more, of a data stream that you have to process in some way. Get my survival guide to generic “iOS coding” interviews here ![🏜️](https://abs-0.twimg.com/emoji/v2/svg/1f3dc.svg) [https://blog.jacobstechtavern.com/p/ios-coding-interview](https://t.co/51SSB5xxgK)