Sort by

recency

|

1930 Discussions

|

  • + 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);
    }
         
    
  • + 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);
    }
         
    
  • + 0 comments

    I have same question.

    But when i try to check manually this is what i found: 12345678 - original 12354678 - bribe 1 12534678 - bribe 2 12534768 - bribe 3 12537468 - bribe 4 12537486 - bribe 5 12537846 - bribe 6 12537864 - bribe 7

  • + 0 comments

    There is one thing I don't understand, can a biber be bribed? for instance * 1 2 3 4 5 * 2 1 3 4 5 * 1 2 3 4 5

  • + 0 comments

    New Year Chaos:

    Sample Test Case 1: 1 2 5 3 7 8 6 4

    8 - 2 bribes

    7 - 2 bribes

    5 - 2 bribes

    total 6 bribes, but the test case is saying 7 bribes? Does anyone know this ?