Minimum Cost Path to visit all nodes situated at the Circumference of Circular Road | Function to find the minimum cost ; Sort the given array ; Initialise a new array of double size ; Fill the array elements ; Find the minimum path cost ; Return the final result ; Driver code
def minCost ( arr , n , circumference ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE arr2 = [ 0 ] * ( 2 * n ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT arr2 [ i ] = arr [ i ] NEW_LINE arr2 [ i + n ] = arr [ i ] + circumference NEW_LINE DEDENT res = 9999999999999999999 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT res = min ( res , arr2 [ i + ( n - 1 ) ] - arr2 [ i ] ) ; NEW_LINE DEDENT return res ; NEW_LINE DEDENT arr = [ 19 , 3 , 6 ] ; NEW_LINE n = len ( arr ) NEW_LINE circumference = 20 ; NEW_LINE print ( minCost ( arr , n , circumference ) ) NEW_LINE