I came across an interesting leetcode problem and decided to solve it in Python (a language I’m not comfortable with) for practice.
Here’s the problem:

Given an unsorted array, find the maximum difference between the successive elements in its sorted form.

Try to solve it in linear time/space.

Return 0 if the array contains less than 2 elements.

You may assume all elements in the array are non-negative integers and fit in the 32-bit signed integer range.

This problem reminded me of an incredible article I read a long time ago. I admit that I drew inspiration from it when solving this question, and writing my code.
The trick is make the pattern compact so for example, we shorten “a*.*” and “a*a*” into “.*” and “a*”

In Python, we can somewhat brute-force this by comparing lengths and adding/reducing “*” and “.*” segments.
We divide it up, compare characters and lengths, and keep matching substrings, etc. (once yousee the code it’ll be more clear)

Overall, the problem is a matter of checking every case, utilizing DFS, and making sure all the cases are covered.

I truly hope this does not appear in any software engineer interview as it was very challenging, at least for me.
If you know a better way to solve this, please let me know!

I apologize in advance if my coding-style is bad. Python is one of my weaker languages and the purpose of doing this problem was to learn.
Obviously, I didn’t read up on detailed styling guides so I just used the automatic formatting feature but I’m unsure if that’s even working properly because it looks kind of off (maybe I’m just so used to Java haha).