How to Calculate the Middle Index?

A good number of interview questions require you to constantly split an array/string in half. This is relatively easy to achieve when the array count is odd. However when the count is even, it’s not as easy. let a = [1,3,8,10,22] // middle index is 2 let b = [1,3,8,10] // middle index is 1.5 which is non-existent. So what now? Most important thing to note is: There’s no such thing as “middle index” when the count is even, I mean there’s two middles in that case....

June 19, 2022 · 4 min

Compress String

Question A simple compression algorithm would be to replace repeating characters with their count. Example aaa --> a3 aaabb --> a3b2 aaabbaa --> a3b2a2 Want to stand out? Ask if there’s a difference between a & A and if you need to add uppercase & lowercase together or need to separate them. In my implementation I assumed they’re different. Code // start counting, then upon seeing a diff, write the count....

June 15, 2022 · 1 min

Check if Two Strings Are One Edit Away

Question You can edit a string in three different ways: insert, remove or replace a character. Write a function to see if two strings are one or zero edits away. Example like, like --> true (zero edits) like, likes --> true (one edit: remove/insert) like, life --> true (one edit, replace) like, lik --> true (one edit: remove/insert) like, pine --> false (two edits) like, lion --> false (two edits) Strategy For most questions that require you to return true or false, you can reduce the scope of the question by removing noise....

June 15, 2022 · 3 min

Swift Strings for iOS interviewing

This is bit of fast paced intro into Swift Strings. ASCII, Unicode and the challenges they introduce. ASCII Ages ago, only characters that existed were just a to z, A to Z, and bunch of other English characters. This was problematic. You were limited to only 7 bits i.e. only 2 ^ 7 - 1 = 127 characters. Also non-English characters where not part of ASCII. Literally the name says ‘American Standard Code for Information Interchange’....

June 12, 2022 · 6 min