• + 0 comments

    Solution for c#

    public static void minimumBribes(List<int> q)
    {
    	int totalBribes = 0;
    
    	for (int i = q.Count - 1; i >= 0; i--)
    	{
    			// if the current person moves than 2 spots
    			if (q[i] - (i + 1) > 2)
    			{
    					Console.WriteLine("Too chaotic");
    					return;
    			}
    
    			// Sum up the bribes
    			for (int j = Math.Max(0, q[i] - 2); j < i; j++)
    			{
    					if (q[j] > q[i])
    					{
    							totalBribes++;
    					}
    			}
    	}
    	Console.WriteLine(totalBribes);
    }