You've been tasked with identifying if there's a color of candy in a bag that represents the majority share of bag. 🍬 The majority element is one which takes up over half of the space in a collection. Given a list of elements representing the colors, return the color found as the majority, otherwise indicate that no majority has been found.
For a simple list, [Red, Red, Blue, Red, Green], the returned value should be Red because Red occurs 3 times out of a list of 5. But for a list [Red, Red, Blue, Green], there is no majority despite Red being the most common element because 2/4 is not greater than half of the elements.
You've been tasked with identifying if there's a color of candy in a bag that represents the majority share of bag. 🍬 The majority element is one which takes up over half of the space in a collection. Given a list of elements representing the colors, return the color found as the majority, otherwise indicate that no majority has been found.
For a simple list, [Red, Red, Blue, Red, Green], the returned value should be Red because Red occurs 3 times out of a list of 5. But for a list [Red, Red, Blue, Green], there is no majority despite Red being the most common element because 2/4 is not greater than half of the elements.