human
Check for each subarray whether it consists of all natural numbers up to its length or not | Function to check if a subarray of size i exists that contain all the numbers in the range [ 1 , i ].
Store the position of each element of arr [ ].
Traverse the array.
Insert the position of arr [ i ].
Store position of each element from the range [ 1 , N ].
Iterate over the range [ 1 , N ].
Insert the index of i into st.
Find the smallest element of st.
Find the largest element of st.
If distance between the largest and smallest element of arr [ ] till i - th index is equal to i.
Driver Code"
Solution in Python:
assistant
#Here is code to check for each subarray whether it consists of all natural numbers up to its length or not and the other steps required.
 def checksubarrayExist1_N ( arr , N ) :
	pos = { }
	for i in range ( N ) :
		pos [ arr [ i ] ] = i
	st = { }
	for i in range ( 1 , N + 1 ) :
		st [ pos [ i ] ] = 1
		Min = sorted ( list ( st . keys ( ) ) ) [ 0 ]
		Max = sorted ( list ( st . keys ( ) ) ) [ - 1 ]
		if ( Max - Min + 1 == i ) :
			print ( " True " , end = " ▁ " )
		else :
			print ( " False " , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 4 , 3 , 2 ]
	N = len ( arr )
	checksubarrayExist1_N ( arr , N )