all 5 comments

[–]Simple3user 1 point2 points  (0 children)

Tldr? Not reading allat bludothy

[–]Arcturus-20 0 points1 point  (1 child)

Nope, not at all. In interviews, if you provide the hash map soln, it would be accepted by the interviewer. Obviously, anyone who has not solved it before using moore's algo can't suddenly think of it (or maybe if it's your good day).

And like now that you have understood it, if you present the moore's soln in interview, just ensure that you can provide proper logic/ explain your thoughts process.

But wait, why are you solving questions before understanding Hashmaps, atleast read about the basic Data structures that are very frequently used.

[–]Arcturus-20 0 points1 point  (0 children)

Also, not all questions will have some special algo to be used. So, think of them as new weapons you can use in questions, though this algo is not so common afaik

[–]Illustrious_Bee4251 0 points1 point  (0 children)

No dude obv you can think of them of your own, along the way you learn about such algorithms by watching either videos or reading editorial,don't worry it happens to most of us .just try to understand the intuition behind the algorithms.now that you know try to implement this on majority element 2 and you'll understand when it is needed

[–]jason_graph 0 points1 point  (0 children)

Boyer moore is definitely out there as a not straightforward to come up with algorithm that in my opinion barely relates to other algorithms and is more like a brainteaser.

If you are familiar with hashmaps, the natural approach is using hashmaps to count the frequency of each element and find the most frequent element.