For Turbo Sort question I have written the below code.
I am getting time limit exceeded error for it.
I have tried the output for the same input given in the question and also for other input and the output is in ascending order.
I was using Scanner object earlier to take input but later changed it to bufferedreader and the earlier one is slower.
Kindly advise any changes in the solution to get AC.
package codechef_flow001;
import java.io.*;
class CodeChef_TurboSort
{
public static void main(String[] args) throws IOException
{
int temp;
BufferedReader kin = new BufferedReader(
new InputStreamReader(
System.in
)
);
int a = Integer.parseInt(
kin.readLine());
int array[] = new int[a];
for(int i = 0; i < array.length; i++)
{
int b = Integer.parseInt(
kin.readLine());
array[i] = b;
}
for (int i = 0; i < array.length; i++)
{
for (int j = i+1; j < array.length; j++)
{
if (array[i] > array[j])
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
for (int a1 : array)
{
System.out.println(a1);
}
}
}