Given an array of integers. Find the maximum number of consecutive integers present in the array. For example, if the array is:
int arr[] = { 2, 24, 22, 60, 56, 23, 25};
Then the answer should be 4, because there are 4 consecutive integers present in the array (22, 23, 24, 25).
Solution:
The brute-force way is to traverse the array, and for each element find the maximum length of consecutive integers present in the array if this element (current element) is the starting point.
Read full article from Maximum consecutive integers present in an array – Ritambhara Technologies – Coding Interview Preparations
No comments:
Post a Comment