Check if array contains contiguous integers with duplicates allowed | Function to check whether the array contains a set of contiguous integers ; Storing elements of ' arr [ ] ' in a hash table 'us   ; As arr [ 0 ] is present in 'us   ; Starting with previous smaller element of arr [ 0 ] ; If ' curr _ ele ' is present in 'us   ; Increment count ; Update 'curr_ele" ; Starting with next greater element of arr [ 0 ] ; If ' curr _ ele ' is present in 'us   ; Increment count ; Update 'curr_ele" ; Returns true if array contains a set of contiguous integers else returns false ; Driver code
def areElementsContiguous ( arr ) : NEW_LINE INDENT us = set ( ) NEW_LINE for i in arr : us . add ( i ) NEW_LINE count = 1 NEW_LINE curr_ele = arr [ 0 ] - 1 NEW_LINE while curr_ele in us : NEW_LINE INDENT count += 1 NEW_LINE curr_ele -= 1 NEW_LINE DEDENT curr_ele = arr [ 0 ] + 1 NEW_LINE while curr_ele in us : NEW_LINE INDENT count += 1 NEW_LINE curr_ele += 1 NEW_LINE DEDENT return ( count == len ( us ) ) NEW_LINE DEDENT arr = [ 5 , 2 , 3 , 6 , 4 , 4 , 6 , 6 ] NEW_LINE if areElementsContiguous ( arr ) : print ( " Yes " ) NEW_LINE else : print ( " No " ) NEW_LINE