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, 2019 in Java by Sneha
738 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, 2019 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,170 points
164 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,200 points
1,264 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,110 points
246 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,370 points
83 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,580 points
190 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,270 points
191 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,200 points
1,757 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,200 points
137 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, 2019 in Java by Wasim
147 views
0 votes
2 answers

What are the different types of constructor in StringBuilder class?

StringBuilder  we 4  as mentioned below. READ MORE

answered Sep 1 in Java by Sri
• 2,970 points
169 views