How to get rid of TLE in Java?

0 votes

I was taking a test, the question asked was to rotate an array by some value provided by user. The user input consisted of number of test cases and in second line length of array and rotate point.

Eg:

1
5 3
1 2 3 4 5
Output
4 5 1 2 3

I have written the program and got the correct answer also but then again I am getting TLE when I submitted the code. Please help me understand what is this TLE and how to get rid of it?

 

Mar 5 in Java by Sneha
214 views

1 answer to this question.

0 votes

The TLE (Time limit exceed) problem occurs due to the time taken by Java to take input and write output using Scanner class which is slow. I know of the two ways and that works absolutely fine.

  1. Avoid using Scanner Class and try to use BufferedReader class.
  2. Try to use StringBuffer class in case you have to print large number of data.
answered Mar 5 by Disha

Related Questions In Java

0 votes
1 answer

How to get the number of digits in an int?

You can find out the length of ...READ MORE

answered May 14, 2018 in Java by Akrati
• 3,150 points
49 views
0 votes
2 answers

How to sort an ArrayList of custom object by property in Java?

You can Sort using java 8 yourList.sort(Comparator.comparing(Classname::getName)); or  yourList.stream().forEach(a -> ...READ MORE

answered Aug 13, 2018 in Java by samarth295
• 2,190 points
96 views
0 votes
1 answer

In Java, how to find out the min/max values from array of primitive data types?

import java.util.Arrays; import java.util.Collections; import org.apache.commons.lang.ArrayUtils; public class MinMaxValue { ...READ MORE

answered Jun 12, 2018 in Java by Daisy
• 8,050 points
93 views
0 votes
1 answer

How to get the IP address of the machine using Java?

One approach is to use NetworkInterface.getNetworkInterfaces() to get all ...READ MORE

answered Jun 25, 2018 in Java by sharth
• 3,350 points
39 views
0 votes
1 answer

Are arrays equivalent to objects in Java ?

Yes; the Java Language Specification writes: In the Java ...READ MORE

answered May 10, 2018 in Java by Rishabh
• 3,540 points
69 views
0 votes
1 answer

Remove objects from an array in Java?

We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,280 points
58 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,190 points
473 views
0 votes
2 answers

What is the syntax to initialize an array?

Rather than learning un-Official websites learn from ...READ MORE

answered Aug 2, 2018 in Java by samarth295
• 2,190 points
56 views
0 votes
1 answer

What are the different ways of comparing Strings in Java?

The different ways of comparing string in ...READ MORE

answered Mar 5 in Java by Wasim
57 views
0 votes
1 answer

What are the different types of constructor in StringBuilder class?

There are different types of StringBuilder constructor ...READ MORE

answered Mar 5 in Java by Mariyam
50 views