So, one year ago, I was solving some problems on LeetCode. I stopped doing them for a while, but now I want to return and try participating in competitive programming. Anyway, here is my little story.
I started solving the Valid Anagram problem (https://leetcode.com/problems/valid-anagram/description/). It is really easy and not that interesting, but I wanted to find a creative approach to solve it. I came across Zeckendorf's theorem (https://en.wikipedia.org/wiki/Zeckendorf's_theorem) and thought it would be perfect to apply to this problem using Fibonacci numbers. I assigned each letter a Fibonacci number (without two consecutive ones) and then found the sum of these numbers for each string and compared them. This solution even passed and had an O(n) complexity. The problem was that I missed the part about needing to have distinct numbers, so it didn't actually work.
Eventually, I created a working solution with a similar concept, but using prime numbers and the Fundamental Theorem of Arithmetic. Here it is: https://leetcode.com/problems/valid-anagram/solutions/3654107/on-solution-using-prime-numbers/
I wonder if there is any other similar or even more creative way to solve this problem. Or perhaps a way to apply Zeckendorf's theorem to it?
In mathematics, Zeckendorf's theorem, named after Belgian amateur mathematician Edouard Zeckendorf, is a theorem about the representation of integers as sums of Fibonacci numbers.
Zeckendorf's theorem states that every positive integer can be represented uniquely as the sum of one or more distinct Fibonacci numbers in such a way that the sum doe...