Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Read a list of integers and find the longest sequence of equal elements. If several exist, print the leftmost.
- Examples
- Input Output
- 3 4 4 5 5 5 2 2 5 5 5
- 7 7 4 4 5 5 3 3 7 7
- 1 2 3 3 3 3
- Hints
- • Scan positions p from left to right and keep the start and length of the current sequence of equal numbers ending at p.
- • Keep also the currently best (longest) sequence (bestStart + bestLength) and update it after each step.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement