HomePagev2 Forums Python Discussions Lists-practice-1 Reply To: Lists-practice-1

  • Akondi Seetharam

    Member
    December 21, 2020 at 11:36 am

    Sorry for not asking the question clearly.

    **Given a list of integers, find the length of the longest range of consecutive integers that are contained in the sorted version of the list.

    In the question in a practice quiz. There was a list and we need to sort it. At that point I used .sort() to convert all the list elements into ascending order.

    But, after that I need to search for the longest range of consecutive integers.

    What I need to do now?

    By taking this list as an example

    [1,3,5,10,13,14,15]

    MY LOGIC:

    Is checking the index value of a number, and the next consecutive number should be a increased by +1. So, that I can obtain the numbers from 13,14,15. Finally I need to print the length.

    Is this the correct way. or is there any other approach.

    Thank you. @satish-vadlamani sir and @Kadhir