• 0

Find length of the largest subarray with contiguous elements

[et_pb_section admin_label="section"][et_pb_row admin_label="row"][et_pb_column type="4_4"][et_pb_text admin_label="Text" background_layout="light" text_orientation="left" text_text_color="#000000" use_border_color="off" border_color="#ffffff" border_style="solid"] Given an array of distinct integers, find length of the longest subarray which contains numbers that can be arranged in a continuous sequence. If the array does not contain the unique elements then we will have to filter the duplicate elements first.


  •  Sort the given array
  •  Iterate through the sorter array and keep track of the longest subarray with continuous elements in another array
  •  Return the maximum number in the result array

Time Complexity

O (n long n)