# Questions tagged [time-limit-exceeded]

When the code scales so poorly in the face of large inputs that it cannot complete in a reasonable amount of time, use this instead of the [performance] tag.

837 questions
Filter by
Sorted by
Tagged with
2k views

### Reverse Game HackerRank Ruby Solution

Problem Statement Akash and Akhil are playing a game. They have N balls numbered from 0 to N−1. Akhil asks Akash to reverse the position of the balls, i.e., to change the order from ...
550 views

### Computation for finding the largest prime factor of 600851475143 is slow

I implemented the following for Project 3 in Project Euler: ...
213 views

### NGON (many polygons) on SPOJ

I am trying to solve NGON problem. I am using bottom up dynamic programming here. Recurrence function is: \begin{array}{rl} f(a,b) &= f(a-1,b) + f(a-1,b-1)\,a_i +\frac{f(a-1,b-2)\,a_i(a_i-1)...
1k views

### Sum the Multiples of 3 and 5

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below N. ...
522 views

### Time Limit Exceeded with Segment Tree data structure

I am trying to solve this problem Chef Ceil has some matchsticks in his kitchen. Detail of matchsticks: There are N matchsticks in total. They are numbered from to 0 to N-1 inclusive. ...
806 views

### Python softmatcher using difflib impracticably slow

I have a softmatch function (below) that takes a donor list and a new entry and looks to see if the given donor already exists. The data is not exact, so I have to use a softmatch to determine ...
300 views

### Testing whether sums of cubes are Fibonacci numbers

I'm trying to iterate through all the combinations of pairs of positive long integers in Java and testing the sum of their cubes to discover if it's a Fibonacci ...
4k views

### Optimizing O(m n) solution for longest common subsequence challenge

Given two strings string X of length x1 and string Y of length ...
285 views

### Speed up counting sort algorithm in Ruby

I'm attempting this simple HackerRank counting sort problem but testcase #3, which has 100,000 test cases, is timing out. Is there something particularly inefficient about this code? ...
388 views

### GSS1 SPOJ problem Time Limit Exceeding

The problem is presented here as follows: You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A query is defined as follows: Query(x,y) = Max { a[i]+a[i+1]+...+...
6k views

### “Rotating the string” optimization

Below is the code for the problem at Codechef. I have made use of the String method .equals in my solution which is working fine ...
2k views

### Prime generator program SPOJ time limit exceed

Problem Statement Input The input begins with the number t of test cases in a single line (t<=10). In each of the next t lines there are two numbers m and n (1 <= m <= n <= ...
3k views

### Binary tree level order traversal algoritm

I am trying to solve this Binary tree lever order traversal: ...
851 views

### Time Limit Exceeded in BFS maze solver

Here's a problem that I tried solving: Lakshagraha was a house built of lacquer, made by the Kauravas to kill the Pandavas. The Kauravas wanted to burn the house down when the Pandavas were ...
246 views

### Painting Tom Sawyer's Fence - programming on Free Pascal

Tom Sawyer has many friends who paints his fence. Each friend painted contiguous part of the fence. Some planks could stay unpainted, some could be painted several times. Program must output the ...
1k views

### STL and Dijkstra's algorithm optimization

This is the problem and my solution to this is: ...
165 views

### Time limit exceeded in Heap

I wrote a Heap, but the judge system reports "time limit exceeded" in some tests. I use a sift_down to build, so I don't know why. Maybe I can improve the build? ...
114 views

### Stored procedure to run a credit-card debt query

This is a stored procedure that takes 5-30+ minutes to run depending on the parameter they select. It also has a nasty side effect of clogging down our SQL Server. ...
328 views

### Central Delannoy numbers

I am solving this problem on SPOJ Upper Right King (Hard): There is a king in the lower left corner of the $n \times n$ chess board. The king can move one step right, one step up or one step up-...
83 views

### Store procedure timing out sometimes

Can someone please find out why this store procedure is timing out? ...
1k views

### Optimizing SPOJ edit distance solution

I was doing a standard problem of DP (dynamic programming) on SPOJ Edit Distance using Python. ...
1k views

### Reducing time limit for prime number program

I have to create a program in which t sets of m and n will be given by the user. For each ...
618 views

### Outputting prime numbers between two numbers

What is the best practice to output a list of prime numbers between two numbers? How can I achieve a better running time? This is a solution to a SPOJ problem which is getting Time Limit Exceeded. <...
2k views

### Hackers Ranking String Similarity

I am currently trying to teach myself some programming. I have started to work with Python by doing this challenge. For each test case, I need to find the sum of the self-similarities of a string ...
6k views

### SPOJ Problem 2 - Prime Generator

I'm trying to solve this problem. After a couple of tries, this is what I pulled off: ...
4k views

### 3n + 1 problem optimization

The problem can be viewed here, since it's styled. I don't think I should just copy and paste. I implemented recessive function and dynamic programming to solve it. It can successfully passed UVa ...
3k views

### Efficient implementation of a Dynamic Programming challenge

I wrote the following code for a Dynamic Programming problem but the online judge gives me a 'Time Limit Exceeded' error. How can I optimize this code to make it more efficient, especially the part ...
787 views

### UVA 10474 - “Where is the marble?” time limit

I have a problem from UVA online judge here. I have read it tons of times, and as they said, I have to get the answer really fast. I have used a binary search and ...
298 views

### “Unfriendly Number” challenge

I tried to solve the Unfriendly Number problem on InterviewStreet: There is one friendly number, K, and N unfriendly numbers. We want to find how many numbers are there which exactly divide the ...
503 views

### Optimization in overcoming TLE in interviewStreet problem

I have been trying to get the problem Quadrant Queries correct for a while now. Although my approach is an optimal one, I am getting a TLE on 3 test cases. Please help me optimize my approach so that ...
300 views

### Mathematical programming puzzles

This is a solution I wrote for a programming puzzle which I believe and I'm sure is correct, but for two of their test cases the online judge gives me 'Time Limit Exceeded' only by a few 100ms! I've ...
2k views

### Handling addition of two binary numbers

This code is for handling addition of two binary numbers, which can be as long as 100,000 bits... and up to 500,000 queries are performed. High-level pseudocode: First input ...
3k views

### Output strings from a set in lexicographical order

Puzzle Description: You are given 'n' strings w1, w2, ......, wn. Let Si denote the set of strings formed by considering all unique substrings of the string wi. A substring is defined as a ...
1k views

### Optimizing string match algorithm

I was trying to solve this problem. I thought of any possible relation between the number of matches among subsequent substrings, but could not find one. So, the probably naive solution that I ...
747 views

### Comparing rows of a matrix with some row vectors

I have run this program for five hours and it has not yet completed. I wonder if we can make changes to reduce the computation time. I use several for loop and this greatly increases the computation ...