The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
4
votes
2answers
2k views

Find palindrome in a string

The purpose of this code is to find the largest palindrome in a string. It works fine when the string is short, but every time I test this code with 1000+ characters in a string, it takes forever to ...
7
votes
4answers
5k 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: ...
5
votes
2answers
75 views

Creating nodes and edges

I'm looking for a way to optimize this piece of code in Python. all_users holds all the Twitter users and friends_ids is an ...
8
votes
3answers
2k views

Given a set of points and pairs of lines, count the number of points that are between the pairs of lines

This is a contest problem. The entire description is here. In resume: The question gives a point simulating a light explosion that always has a negative x coordinate, a set of pairs line segments on ...
4
votes
2answers
324 views

Ruby Interrupted Bubble Sort

Working through CodeEval's Interrupted Bubble Sort, I have a working algorithm, but there's a speed issue. I'm trying to do this with Ruby and I keep getting an error that it's timing out after 10 ...
11
votes
5answers
814 views

Reversing a number

I was working through a programming challenge I found on Reddit and it seemed easy enough: Find all numbers less than \$10^n\$ where the number and its reverse (the reverse of \$123\$ is \$321\$) ...
7
votes
3answers
837 views

Finding the shortest excerpt that contains all search terms

Write a function called answer(document, searchTerms) which returns the shortest snippet of the document, containing all of the given search terms. The search ...
2
votes
1answer
143 views

“Little Deepu and Array” challenge

I'm trying to solve this problem. I changed Scanner and used BufferedReader but I'm still getting TLE with the given code. Can I ...
3
votes
2answers
170 views

“Sherlock and the Beast” challenge in Java

I have been trying to solve the following problem on hackerrank.com, but when I submit the code it shows unsuccessful submission due to timeout. Can anyone help me out? Sherlock and the Beast ...
19
votes
3answers
926 views

Enigma machine simulator - improving recursive algorithm performance

I'm new to Haskell and am confused by why my code seems to preform so poorly, and wonder if there's something I've not grasped about the coding philosophy behind the language, or the best way to take ...
5
votes
3answers
595 views

SPOJ solution of GRAVITY

I am solving problem GRAVITY on SPOJ. Each test case is a rectangular ASCII grid of dimensions m × n, and you have to determine ...
5
votes
1answer
229 views

Project Euler, Challenge #12 in Swift

The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, ...
4
votes
1answer
419 views

Project Euler 91 (via HackerRank): Right triangles with integer coordinates

This is my code to solve HackerRank's version of Project Euler Problem 91: on an N × N grid, find the number of possible right triangles where one vertex is (0, 0) and the other two vertices are ...
6
votes
3answers
8k views

E-mail MIME message parser

As part of a larger Java application I'm working on, I have to retrieve emails and parse the data for the emails' content (subject, date, text, attachments, sender). In the method below, I pass a <...
3
votes
1answer
882 views

Seeking 5 primes such that concatenating any two of them produces another prime

I have a program which solves Project Euler problem 60: The primes 3, 7, 109, and 673, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be ...
4
votes
3answers
6k views

Calculating the sum of array elements to the left and right

I am using C++ to code the following logic: An Array is given we have to traverse the array such that sum of array elements to its left must be equal to sum of elements to its right. BTW this is ...
4
votes
1answer
594 views

HackerEarth Challenge Find Maximum Taste of Fruits

Problem Statement: Samu had got N fruits. Sweetness of ith fruit is given by A[i]. Now she wants to eat all the fruits , in such a way that total taste is maximised. Total Taste is ...
0
votes
2answers
182 views

Codechef COOKMACH solution, exceeding time limit

I'm stuck on Codechef problem COOKMACH, which asks for the minimum number of operations needed to transform integer A into integer B, where each operation can be either doubling the number or halving ...
12
votes
1answer
155 views

Finding the balancing point of a subsequence

This is a little tricky to explain, so bear with me. Suppose you have an integer X and a list of integers A. Let ...
-1
votes
1answer
831 views

Reading QR Code

What I need to accomplish is matching the QR code to the one I have created. This code works, except it takes at least 30 seconds to verify that it has matched my QR Code. How can I make it faster? ...
-2
votes
1answer
283 views

“Finding possible candy permutations” HackerEarth challenge

Problem Statement Shil, Aditya and Utkarsh go to a candy shop. There are N candies present in the shop, which are indexed from 1 to N. All three of them select one candy to eat. However, ...
1
vote
3answers
168 views

Performing add/delete/count operations on a list

Problem Statement (HackerRank) You have a list of integers, initially the list is empty. You have to process Q operations of three kinds: add s: Add integer s to your list, note that ...
2
votes
5answers
4k views

Find perfect squares between two numbers

The following problem is from codechef.com: Recently Chef become very much interested in perfect squares. We all know Chef and his weird interests. Anyways Chef will be soon writing his masters ...
1
vote
1answer
320 views

SPOJ - POWFIB (Fibo and non fibo) Time Limit Exceeds

Problem Find (a^b)%M, where a = Nth non-fibonacci number b = Nth fibonacci number modulo M M = 1000000007 Consider fibonacci series 1,1,2,3,..... INPUT First line ...
1
vote
4answers
2k views

Checking whether a graph is bipartite using BFS

I am solving a simple problem that checks whether a graph is two-colourable (bipartite graph). I am using BFS for this approach using C++ STL. I've replaced cin and ...
5
votes
3answers
707 views

Counting number of inversions

This is a HackerEarth Challenge Problem. Question: Puchi hates to carry luggage, but unfortunately he got a job to carry the luggage of his N friends in office. Each day, one of his N friends,...
5
votes
1answer
408 views

Sudoku-solving program

This is a Sudoku solver program which uses backtracking. It is a problem from Online Judge and I made it work after some struggle, but it needs to be faster as I'm getting a Time Limit Exceeded ...
4
votes
3answers
288 views

Finding the tallest and find the index number of the next taller guy in a circular queue

Input given is: Each test case contains two lines. The first line contains a single integer N (1 ≤ N ≤ 105), the number of persons playing the game. The second line contains N integers i(height) (1 ...
2
votes
2answers
432 views

ProjectEuler Problem #3

I'm working on projecteuler.net problems, and I made this for problem #3: ...
12
votes
3answers
869 views

Speeding up spectrum analysis

I'm trying to speed up this code that loops over an entire spectrum range. It's using a Raspberry Pi, and a rtl-sdr dongle that covers up to around 1.7 GHz. My goal is to be sweep over that spectrum ...
13
votes
5answers
8k views

“Algorithmic Crush” problem hitting timeout errors

This is the HackerRank problem Algorithmic Crush: You are given a list of size N, initialized with zeroes. You have to perform ...
4
votes
2answers
744 views

Calculating sum of smallest prime factors for 2 < n < 10**12

I am trying to calculate the sum of the smallest prime factors of n, where 2 < n < 10**12, and get the remainder of this ...
3
votes
2answers
858 views

Euler 357 solution efficiency

I have a Ruby program which should solve the following problem: Consider the divisors of 30: 1,2,3,5,6,10,15,30. It can be seen that for every divisor d of 30, d+30/d is prime. Find the sum ...
0
votes
1answer
106 views

jQuery-loaded financial report taxes the browser

I load a table in a div using the .load() method. If I look on the console I see the times taken to display the table: 4.98 seconds that firebugs says are spent "...
7
votes
3answers
784 views

Rating tennis players in a database, taking days to run

I have this project in data analysis for creating a ranking of tennis players. Currently, it takes more than 6 days to run on my computer. Can you review the code and see where's the problem? ...
10
votes
2answers
556 views

Minimum sub-array challenge

Below is my solution to finding the minimum product sub-interval. It passed 8/12 or so test cases, but the other test cases timed out if they hadn't finished within 2 seconds. When I compile this code ...
2
votes
1answer
200 views

INTEST on Codechef in Python 3

I have written a program in Python 3 for the INTEST problem on Codechef (included in question). The program is taking a lot of time (55.76s) in Python 3. The same code takes almost 1/10 of the time ...
2
votes
2answers
2k views

Speedup for Project Euler 44 - pentagon numbers

I'm trying to solve the problems of Project Euler with Haskell within less than 10s with optimized code (ghc -O2). Unfortunately, I'm struggling to find a correct ...
2
votes
3answers
184 views

Project Euler problem 12: highly divisible triangular number

I am just a beginner in C++ and I tried solving this problem: What is the first number of the form 1 + 2 + 3 + … + n that has over five hundred factors? But it seems my code is not that efficient ...
7
votes
1answer
3k views

Calculate the running median

I'm trying to solve a challenge where you need to calculate the median every time you add a number. say you have a list of numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ...
5
votes
3answers
716 views

Phone List challenge

To learn Haskell, I've been going at this challenge, which is to check a list of phone numbers to ensure that no number is a prefix of another. However, my code is way too slow. I am really new to ...
11
votes
3answers
8k views

Finding the intersection of two sets of integers

I need to pass a programming exam in order to graduate but I'm having a hard time passing it because most of my programs are too slow. Can someone give me some tips on how to make my programs faster ...
3
votes
3answers
3k views

Number of right cyclic shifts to give the biggest number

I am preparing to coding interview and I met this task today: You are given 30-bit unsigned integer N. A right cyclic shift of N by K bits is the result of performing a right cyclic shift of N by one ...
3
votes
3answers
446 views

Merging Digital River

I am solving this question: It's not the rivers that you might be thinking about. The question revolves around the concept of digital rivers. A digital river is a sequence of numbers where the ...
5
votes
1answer
98 views

Optimal way to annihilate a list by removing items from the ends

I'm stuck with a contest problem. Description: What is the minimum number of moves to annihilate an int array where the possible moves are: Remove both the first and last elements if they are equal ...
1
vote
3answers
2k views

Isomorphic Strings

Two strings are isomorphic if the characters in s can be replaced to get t. Can efficiency be increased further for this code? ...
4
votes
3answers
5k views

Print the number of unique pairs Stored in a HashSet

I'm trying to solve this fairly straight forward challenge: Problem Statement In computer science, a set is an abstract data type that can store certain values, without any particular order, ...
2
votes
1answer
470 views

SPOJ “SBANK - Sorting Bank Accounts” TLE

I am new tro programming and have chosen python 2.7 to begin with. But, I often have to deal with a TLE while competitive coding like in the problem below, where my code runs fine on all test cases ...
8
votes
5answers
5k 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?...
3
votes
2answers
766 views

Project Euler #12 runs very slowly

The problem is : The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: ...