We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My solution was in C#. The JVM and .Net VM probably have different performance characteristics. If you're still getting timeout without having any sort at all, then there's probably something going on in the sections where you load.
I did just try it, and Test Case 6 fails with a timeout if you just use the Java template code.
So Java is unable to even LOAD the test case fast enough.
The issue is with Scanner for reading the input. Use Buffered reader instead and NoneCares sort works perfectly fine.
private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
int n = Integer.parseInt(reader.readLine());
String[] unsorted = new String[n];
for (int i = 0; i < n; i++) {
String unsortedItem = reader.readLine();
unsorted[i] = unsortedItem;
}
String[] result = bigSorting(unsorted);
for (int i = 0; i < result.length; i++) {
bufferedWriter.write(result[i]);
if (i != result.length - 1) {
bufferedWriter.write("\n");
}
}
bufferedWriter.newLine();
bufferedWriter.close();
reader.close();
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Big Sorting
You are viewing a single comment's thread. Return to all comments →
My solution was in C#. The JVM and .Net VM probably have different performance characteristics. If you're still getting timeout without having any sort at all, then there's probably something going on in the sections where you load.
I did just try it, and Test Case 6 fails with a timeout if you just use the Java template code.
So Java is unable to even LOAD the test case fast enough.
The issue is with Scanner for reading the input. Use Buffered reader instead and NoneCares sort works perfectly fine.