Mainly web development for money. Everything else for fun :) Rust, WebAssembly, Flutter, ML, C64 Assembly, Raspberry, ... a lot of plans, much less free time to work on them.
You can try to go in backward direction whule comparing char by char without strings creation. In best case you will determine that strings are different at first iteration. At worst - iterate for max(n, m) times. And in any case you will only need constant extra memory allocation
I am a full stack engineer, passionate about solving complex problems and collaborating with driven teams! I have 4+ years of experience working at small to mid sized startups.
I think a stack-based solution is the most efficient and readable method, to be fair...
If we think about the complexity it should be around O(n)
(n (to compute first) + n (to compute second) + n(to go once over both))
Which is ofc not as good as the O(log(n)), but I am not sure there's a way to cut times.
But... to be 100% correct, in order to determine if this is helpful or just added time for our average case we would need to know the context a bit more in depth.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I can't think of anything else other than a stack-based solution.
You can try to go in backward direction whule comparing char by char without strings creation. In best case you will determine that strings are different at first iteration. At worst - iterate for max(n, m) times. And in any case you will only need constant extra memory allocation
Love the stack based approach!
I think a stack-based solution is the most efficient and readable method, to be fair...
If we think about the complexity it should be around O(n)
(n (to compute first) + n (to compute second) + n(to go once over both))
Which is ofc not as good as the O(log(n)), but I am not sure there's a way to cut times.
Also we can do a sneaky trick such as
But... to be 100% correct, in order to determine if this is helpful or just added time for our average case we would need to know the context a bit more in depth.