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
2,519 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 ascii value of char in java

In Java, you can get the ASCII ...READ MORE

answered Nov 24, 2023 in Java by Zoya
372 views
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,190 points
932 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 14, 2018 in Java by samarth295
• 2,220 points
3,006 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,140 points
1,629 views
+1 vote
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,620 points
1,292 views
+1 vote
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,290 points
1,163 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,220 points
3,528 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,220 points
958 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
955 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, 2020 in Java by Sri
• 3,190 points
1,331 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP