How can I get min move required to sort color balls in tubes.
Solution
It depends what sorting algorithm you’re using. If you assign the colors a number (such as red = 1 and blue = 10) and sort the list using C#'s built-in sorting algorithm (intro-sort - a hybrid sorting algorithm of quicksort and heapsort) you can sort it very quickly. Like, very very quickly. (1 million items took me 0.1 seconds).
However, you won’t be able to implement a method of counting how many moves you would need to sort the list, unless you implement your own quicksort/heapsort/mergesort/bubblesort and increment a counter value every time you move a number/coloured ball.
Sorting Algorithm to use
I would recommend learning mergesort or quicksort and implementing your own version, since they aren’t as difficult to implement but are very effective, giving you the minimum number of moves. If you’re using a small data set of like 16 numbers or less, bubble sort or insertion sort would work fine as well. They’re very easy to implement but only solid for smaller data sets.
@mian_abdul