Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    In fact, this will need to be done in any case, even if it is the first method call. In the worst case scenario where the searched element is the last, this will not be very good for large volumes of data, as was indicated in the condition

  • Custom User Avatar

    If you look at it from a performance point of view, this solution will benefit when compared with a solution that uses Sequence. During my research, Sequence takes between 5 and 13 seconds, while a solution based on while takes 0 seconds

  • Custom User Avatar

    It certainly looks elegant and functional, but I dug deeper into how Sequence works and how effective they are for small sets or sequences. As a result, using the measureTimeMillis function, I found that executing generateSequence with subsequent processing takes from 5 to 13 seconds. While if you use "do{}while(...)" or just "while" it takes 0 seconds. From this we can conclude that although Sequence is very concise and saves us from mutability and temporary variables, we still need to be careful when using them for such tasks.

    I think this is clever but definitely not best practice.