Another day, another LeetCode question (for now). Today, I'm running through #14 on LeetCode, Longest Common Prefix. The input provides an array of strings, with the goal of returning the longest common prefix (the longest string with no characters before it) among the strings, with an empty string if none exist. My initial approaches and implementation was pretty overkill as I misread prefix and interpreted it as a common substring (coincidentally a LC medium, we'll get to it soon), but ultimately I used a sort of "n pointers" approach that checked the value of each string at a shared index, returning whatever common substring has been built up if the values do not line up.
I work in Kotlin as my LeetCode programming language because my current focus is on Android app development. Kotlin is interoperable with Java, so the solution should be relatively similar albeit with some more boilerplate checks for nulls and such.
Current Grind:
Grind75 list, 22 weeks/7 hours per week, [31/169]
(https://www.techinterviewhandbook.org...)
Chapters:
00:00 - Opening, a lot of failure
01:13 - Realization of my mistake and proper "n pointers" solution