If the next element is not consecutive to the current element then stop the iteration.Else, iterate through the array and check whether the next element to the current element is consecutive and increment the current value.If the length of the array is zero then return zero as the output.Then declare two variables to track the current length and maximum length of consecutive numbers found in the array. First, sort the array using any one of the in-place sorting algorithms.We are given an unsorted array of integers, we have to find the longest consecutive sequence in the array. In this article let us look into a medium-level array problem Longest Consecutive sequence with a solution. Learning some such algorithms and practicing some quality problems may help one to increase problem-solving skills and crack many technical interviews with ease. There are a lot of algorithms available to solve the problems with an efficient solution.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |