Skip to content

Instantly share code, notes, and snippets.

@buggysolid
buggysolid / gist:feebd456b4ba98ae9f562f35f9370818
Created August 8, 2022 07:45
Find longest sequence of 1’s in binary representation with one flip
"""
https://www.geeksforgeeks.org/find-longest-sequence-1s-binary-representation-one-flip/
Input : 1775
Output : 8
Binary representation of 1775 is 11011101111.
After flipping the highlighted bit, we get
consecutive 8 bits. 11011111111.
Input : 12
"""
You are given a list of integers. Write code to find the majority and minorty numbers in that list.
Definition: a majority number is the one appearing most frequently, a minority number appears least frequently.
Here is a simple example how it should work:
>>> numbers = [1, 2, 2, 3, 2, 3]
>>> major_n_minor(numbers)
(2, 1)