Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

Find consecutive segments in an sorted array

Problem :

Number list compressing. Given an sorted array. Input: sorted number list [ 1, 2, 3,10, 25, 26, 30, 31, 32, 33]
Output: find consecutive segments print: 1-3, 10, 25-26, 30-33

Logic :

  • We need three-pointers to solve this
    • First which stays at the start of the sequence,
    • Second which stays at the end of the sequence,
    • Third which iterates over the array

Solution :

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *