Minimum Cost Path to visit all nodes situated at the Circumference of Circular Road | C # implementation to find the 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 readonly result ; Driver code
using System ; class GFG { static int minCost ( int [ ] arr , int n , int circumference ) { Array . Sort ( arr ) ; int [ ] arr2 = new int [ 2 * n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr2 [ i ] = arr [ i ] ; arr2 [ i + n ] = arr [ i ] + circumference ; } int res = int . MaxValue ; for ( int i = 0 ; i < n ; i ++ ) res = Math . Min ( res , arr2 [ i + ( n - 1 ) ] - arr2 [ i ] ) ; return res ; } public static void Main ( String [ ] args ) { int [ ] arr = { 19 , 3 , 6 } ; int n = arr . Length ; int circumference = 20 ; Console . WriteLine ( minCost ( arr , n , circumference ) ) ; } }