TheAlgorithms/Java

[OTHER] Make `BoyerMoore.findmajor` return `java.util.Optional<Integer>`

vil02 opened this issue ยท 5 comments

What would you like to share?

Current implementation of BoyerMoore.findmajor returns -1 in case when there is no majority element. This is confusing, since the input array could contain -1. I suggest to change this method to return java.util.Optional<Integer>.

Additional information

Solving this is a goof opportunity to clean up the existing code, I would suggest to introduce new private methods like findCandidate, calculateOccurrences and isMajority.

Could you assign this issue to me?

@prathameshpowar1910 when you will create a PR closing this, please mention me.

@vil02 i have opened a PR #4951 but the build is failing could you look into it?

@vil02 There is some issue with the linting could you solve that?

Solved by #4951.