HTML & JS
using System;

    class Program
    {
        static void Main(string[] args)
        {
            int testCases = int.Parse(Console.ReadLine().Trim());

            while (testCases-- > 0)
            {
                int arrSize = int.Parse(Console.ReadLine().Trim());
                string[] arr = Console.ReadLine().Trim().Split(' ');

                for (int i = 0; i < arrSize - 1; i++)
                {
                    if (int.Parse(arr[i]) > int.Parse(arr[i + 1]))
                    {
                        Console.Write(arr[i + 1] + " ");
                    }
                    else
                        Console.Write("-1" + " ");
                }
                Console.Write("-1");
                Console.WriteLine();
            }
        }
    }

Generated URL:

Output:

2 1 -1 3 -1
-1 2 -1 1 -1 -1
Report Bug