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.

Filter by
Sorted by
Tagged with
10
votes
9answers
5k views

Find the nth prime between 1 and 1,000,000 in under 3 minutes - follow-up

Previous question: Checking for the nth prime number between 1 and 1,000,000, must compute 1,000,000th in under 3 minutes My mission is to find the nth prime number, based on user input 1-1,000,000. ...
4
votes
1answer
348 views

CodeEval Sequence Transformation

I've been working on this challenge for a week: There are two sequences. The first sequence consists of digits "0" and "1", the second one consists of letters "A" and "B". The challenge is to ...
6
votes
2answers
863 views

Project Euler #48 in C++

This question is similar to Project Euler #48 but constraints are different: $$N < 2000000$$ Just in case the link is unavailable, here is the problem statement: We've to print $$\left( \sum_{...
4
votes
2answers
216 views

“Cool Guys” CodeChef challenge

I was trying to solve a question on CodeChef. My code works perfectly fine in my IDE (Visual Studio here) but when I submit my code at CodeChef, it says "Time Limit Exceeded". What the code does: ...
13
votes
3answers
1k views

Optimisation of palindrome

My program takes as first input the number of test cases, n. For the following n inputs, I output the smallest positive integer that has to be added to the input to make the input a numeric palindrome....
-1
votes
2answers
365 views

Fastest way to find maximum deviation

I acknowledge that this exact question was asked here. I was working on the same problem from the same website. I had the same question and consulted the above as a reference, however with respect ...
3
votes
1answer
114 views

Determining average of integers using quicksort

I was attempting an online problem given on a programming website which asked us to tell us the number of integers in a given list which can be obtained as an average of any two other integers in that ...
3
votes
5answers
120 views

All Possible Products

I'm trying to find all possible product of two 3-digit numbers. When I work with small ranges, I'm able to get an output almost instantly but when the ranges are big, it seems to take really long time....
2
votes
3answers
821 views

CodeChef Matrix Rotation

I am new to C# and have tried to solve a problem statement from CodeChef: Problem statement You are given an array A of N integers. You are to fulfill M queries. Each query has one of the ...
-2
votes
2answers
2k views

“ChocolatesByNumbers” challenge

Here is a problem I have attempted: Two positive integers \$N\$ and \$M\$ are given. Integer \$N\$ represents the number of chocolates arranged in a circle, numbered from 0 to \$N − 1\$. You ...
2
votes
3answers
1k views

“Fun with Rotation” - Codechef September Challenge

Can you please help me in reducing the complexity of the below code? The problem statement can be found here. You are given an array A of N integers. You are to fulfill M queries. Each query has ...
7
votes
5answers
2k views

Removing the largest values encountered so far in a list

The problem is, in summary: A set of values will be given. Whenever the input is -1, the largest number from the values inputted until then needs to be printed, and is then deleted. Here is the ...
2
votes
1answer
305 views

Slow Python text-processing script

This script of mine merges columns 1 and 2 from one input file and sees if these merged combinations exist in the other infile (and vice versa). I know I get stuck in appending. It did not get past ...
2
votes
2answers
146 views

“Reverse Groups” challenge

I'm trying to do the Reverse Groups Challenge on CodeEval: Given a list of numbers and a positive integer k, reverse the elements of the list, k items at a time. If the number of elements is not a ...
4
votes
1answer
589 views

Project Euler #12 very long runtime

Project Euler Problem 12 asks to find the value of the first triangular number to have over 500 divisors, where the \$n\$th triangular number is \$\sum_{i=1}^{n} i\$. The sequence of triangle ...
5
votes
2answers
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 ...
4
votes
1answer
612 views

Computation for finding the largest prime factor of 600851475143 is slow

I implemented the following for Project 3 in Project Euler: ...
4
votes
1answer
214 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)...
1
vote
3answers
2k 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. ...
6
votes
2answers
548 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. ...
4
votes
1answer
1k 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 ...
2
votes
2answers
303 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 ...
5
votes
2answers
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 ...
3
votes
3answers
298 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? ...
2
votes
1answer
405 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]+...+...
4
votes
2answers
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 ...
5
votes
2answers
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 <= 1000000000, n-...
5
votes
1answer
3k views

Binary tree level order traversal algoritm

I am trying to solve this Binary tree lever order traversal: ...
4
votes
2answers
890 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 ...
3
votes
1answer
521 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 ...
4
votes
2answers
1k views

STL and Dijkstra's algorithm optimization

This is the problem and my solution to this is: ...
4
votes
3answers
170 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? ...
1
vote
2answers
121 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. ...
6
votes
2answers
335 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-...
1
vote
2answers
83 views

Store procedure timing out sometimes

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

Optimizing SPOJ edit distance solution

I was doing a standard problem of DP (dynamic programming) on SPOJ Edit Distance using Python. ...
2
votes
2answers
2k 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 ...
4
votes
1answer
627 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. <...
6
votes
3answers
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 ...
1
vote
1answer
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: ...
9
votes
3answers
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 ...
6
votes
2answers
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 ...
3
votes
2answers
819 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 ...
2
votes
1answer
320 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 ...
2
votes
2answers
504 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 ...
3
votes
1answer
305 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 ...
5
votes
2answers
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 ...
3
votes
1answer
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 ...
7
votes
1answer
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 ...
0
votes
1answer
749 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 ...