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.
103
questions
9
votes
2
answers
917
views
Prime generator for SPOJ
I have written code to solve the prime generator problem. I am given an input which contains in the first line the number of test cases, and for each test case, I am given a range and I have to print ...
2
votes
3
answers
1k
views
LeetCode 49: Group Anagrams
I'm exceeding the time limit for a 10,000 word test case provided on LeetCode:
Given an array of strings, group anagrams together.
For example, given: ...
151
votes
17
answers
20k
views
Disproving Euler proposition by brute force in C
I wrote a little bit of code to brute force disprove the Euler proposition that states:
$$a^4 + b^4 + c^4 = d^4$$
has no solution when \$a\$, \$b\$, \$c\$, \$d\$ are positive integers.
I'm no ...
14
votes
2
answers
3k
views
O PC, why are you so slow?
In order to test some software I've written, I need to write values to a test harness with OLE for Process Control (OPC). The problem is, for a larger range of values I'm generating points for (say ...
12
votes
4
answers
13k
views
Finding the first duplicate in an array
My code returns the correct answer the first duplicate is 3 (represented as int f) . I am struggling finding a more efficient way to find the first duplicate?
My ...
9
votes
5
answers
6k
views
Euler #3 largest prime factor
Problem Statement
This problem is a programming version of Problem 3 from projecteuler.net
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of a given number N?...
8
votes
2
answers
6k
views
BFS shortest path for Google Foobar "Prepare the Bunnies' Escape"
This is the Google Foobar puzzle "Prepare the Bunnies' Escape":
You have maps of parts of the space station, each starting at a prison
exit and ending at the door to an escape pod. The map ...
7
votes
4
answers
6k
views
Hacker Rank - Poisonous Plants
I have the solution for the problem, but it is taking me 7 seconds to run on a large dataset. I am trying figure out a better way of doing this. It has to run in under 3 seconds.
Problem Statement:
...
4
votes
2
answers
7k
views
Codewars: Sum of Pairs
I've been working on this task (see screenshot).
Here's my answer to it so far:
...
4
votes
1
answer
394
views
Counting ways to fit bottles in crates
I'm calculating how many possibilities there are to fit \$n\$ identical bottles inside \$k\$ crates of various capacities.
n = Number of bottles
k = Number of crates
K = List of the number of bottles ...
3
votes
1
answer
569
views
HackerRank New Year Chaos: arriving at a given list using neighbor swaps
I am trying to solve the HackerRank New Year Chaos problem where the aim is as follows:
A vector of size n is having values ...
2
votes
2
answers
766
views
Printing all the prime numbers between two bounds
I keep getting a time limit exceeded for this solution to SPOJ Prime1. I need to print all primes within a given interval (with intervals as large as 105, and numbers as large as 109).
I've tried ...
1
vote
2
answers
258
views
Closest Pair of Points - Optimizing Code for big sets of points
I'm trying to create an algorithm that finds the closest pair of points (2D) within a set of points. I'm using a divide and conquer method which is explained here Closest Pair of Points Algorithm.
...
18
votes
5
answers
3k
views
Flipping coins performance
This is the Flipping coins problem on CodeChef:
There are \$N\$ coins kept on the table, numbered from \$0\$ to \$N - 1\$. Initially, each coin is kept tails up. You have to perform two types of ...
14
votes
4
answers
4k
views
2-sum problem on a range in Python
Here is the problem description (from an algorithm course: https://www.coursera.org/learn/algorithm-design-analysis):
The goal of this problem is to implement a variant of the 2-SUM
algorithm (...