HomePagev2 Forums Python Discussions Lists-practice-1

  • Lists-practice-1

  • Akondi Seetharam

    Member
    December 21, 2020 at 6:27 am

    waiting for any hints for solving this question.

  • kadhiresan

    Member
    December 21, 2020 at 8:25 am

    What is your question?

  • Satish Vadlamani

    Administrator
    December 21, 2020 at 10:33 am

    @akondiseetharam like @Kadhir I took have the same question, what is your question. The best way to ask is by posting the question and the your attempt or idea. Not everyone has seen the quiz questions. Please, post the question itself and your idea/ logic.

  • 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

    • narendra

      Member
      December 21, 2020 at 1:19 pm

      yes, your logic is correct. Basically, you can check if the next number exists; if exist -> increase the counter to +=1 else reset the counter to 0

  • Satish Vadlamani

    Administrator
    December 22, 2020 at 12:20 pm

    @akondiseetharam did @narensahu answer help you? Need more tips?

  • Satish Vadlamani

    Administrator
    December 22, 2020 at 12:26 pm

    @Kadhir how would you have solved it? Thoughts? I am sure everyone reading this would love to see different perspective

Log in to reply.

Original Post
0 of 0 posts June 2018
Now