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
1answer
123 views

Migrate files from MySQL BLOBs to PostgreSQL largeobjects

As title says, this piece of code migrates files (binary and metadata) from a database to another one with different structure. Currently my problem is that when I have to deal with a big database (...
3
votes
3answers
455 views

Calculate the sum of all primes less than 2,000,000 in Swift

This is a Swift program I wrote to calculate the sum of primes below 2 million, but it is tediously slow. I am curious about what makes it so slow. My theory is that copying the filtered array is ...
4
votes
1answer
991 views

Finding the similarity between the two movies using Pearson correlation coefficient

I am trying to find the similarity between the two movies using Pearson correlation coefficient. The programs is working well for small inputs but for large inputs (like 100000 lines) it takes forever....
2
votes
1answer
689 views

Knight's tour code

Another one for some late night snack. - Knight's tour! Please provide your suggestions/flaws/optimization to this knight's tour backtracking code.. ...
0
votes
1answer
604 views

Partitions of a number (backtracking) - time efficiency

I had to write an algorithm that prints the partitions of a natural number in lexicographic order. Example of I/O: If the algorithm reads from ...
5
votes
1answer
591 views

Number of divisors of a factorial

I was solving the DIVFACT problem from Sphere Online Judge: Given a number, find the total number of divisors of the factorial of the number. Since the answer can be very large, print the answer ...
3
votes
1answer
2k views

Project Euler #549: Divisibility of factorials

This is the problem: Calculate $$\sum_{i=2}^{10^8} s(i)$$ where \$s(n)\$ is the smallest \$m\$ such that \$n\$ divides \$m!\$. Quite mathematical, I've found a better way than brute ...
2
votes
1answer
654 views

CUDA brute force 48 bit key

I have a cryptographic function with two 24 bit keys. I have two blocks of input and two blocks of output, and want to brute force the keys using CUDA. Overview: The function is composed to two ...
2
votes
1answer
501 views

Primes & Squares

Codeforces #230B Question Whether a number has exactly three factors. (i.e. 1, itself and its square root, thus squares of primes) [Time limit is 2 sec, Memory 256 MB] Input Number of testcases, n ...
3
votes
1answer
2k views

Finding the maximum distance from the starting node

I've tried everything to make my program faster but with 250 nodes my code takes around 9 seconds to print the result, and with 5000 nodes it took around 260 seconds. Is there a way to make my ...
2
votes
0answers
389 views
2
votes
2answers
1k views

Counting pairs of integers which have a predefined difference

I'm doing this HackerRank problem: Given \$N\$ integers, count the number of pairs of integers whose difference is \$K\$. So far, I've ended up with this code: ...
-2
votes
3answers
2k views

Generating a very long random string of letters

I was trying to fill a file with about ten million random characters (a-z,A-Z,' '). To my surprise the code is extremely slow. I inserted this print ...
4
votes
0answers
208 views

Time Limit Exceeded with shortest path algorithm

The problem: SHPATH You are given a list of cities. Each direct connection between two cities has its transportation cost (an integer bigger than 0). The goal is to find the paths of ...
1
vote
1answer
676 views

SPOJ DIVSUM - DIvisor Summation

DIVSUM - Divisor Summation #number-theory Given a natural number n (1 <= n <= 500000), please output the summation of all its proper divisors. Definition: A proper divisor of a natural ...
3
votes
2answers
158 views

Copying lists into columns of a table

Edit: I found a potential solution. Changing all of the Dim as Long to Dim as Integer allows the scripts to run smoother. ...
4
votes
4answers
415 views

Copying orders and prices into another Excel sheet

I would like to know if the below VBA can be streamlined to process faster, since it takes on average 9hrs to complete a sheet (800 000 lines), and I have quite a few to get through. Running on 3 ...
4
votes
2answers
677 views

Google Code Jam Google String problem: a sequence resulting from bit flips and reversals

I'm currently having a go at some past Google Code Jam problems to help me practice my programming skills. One of these problems is Problem A ("Googol String") from Round A APAC Test 2016. Here is ...
0
votes
1answer
202 views

Effective ways to find partial sha1 collision

I need to find 2 different string and compare their hash value. Both string must contain "abc". I looking for the first eight character that are the same and stop. I have been running for more than 24 ...
-1
votes
3answers
124 views

Calculating the max difference between any 2 numbers from an array

How can I make this little program work a little faster? The task is to calculate the max difference between any 2 numbers from an array of numbers. Target time is 1 sec, now it works in 1.1 sec. I'...
2
votes
1answer
811 views

Prime generator SPOJ problem in Python 3

I am trying to solve an SPOJ problem: print all prime numbers in a given range (as large as \$10^9\$). I have used the Sieve of Eratosthenes algorithm. But it is still slow when input is in range of \$...
2
votes
2answers
129 views

SPOJ “TESSER” - Getting TLE using KMP algorithm

The TESSER - Finding the Tesserect problem is tagged as a problem to be solved by Knuth-Morris-Pratt (KMP) algorithm. I'm using KMP, but am still getting time-limit-exceeded. Task Each of T test ...
2
votes
3answers
2k views

Determine Collatz sequence length for given starting values

I am trying to get into the habit of solving programming puzzles in my spare time but am stuck on the first one (which I know can be for a large number of reasons, hence my posting for help). Shown ...
5
votes
2answers
803 views

High execution time of LCS length program in Python2

I was trying to solve the Longest Common Subsequence problem on a HackerRank exercise. It's quite simple and straightforward, just print out the length of the LCS. I submitted this code: ...
4
votes
2answers
1k views

Swift solution to Leetcode “Longest Substring Without Repeating Characters”

From LeetCode medium 3. Longest Substring Without Repeating Characters: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", ...
2
votes
1answer
426 views

Union Find implementation

I am trying to complete this challenge. The user should enter a sequence of instructions, = to link two numbers, and ? to query ...
3
votes
1answer
242 views

Chopsticks Game in Python (Version 2)

This is another iteration of my previous question. This program plays the game Chopsticks using the Minimax algorithm. I search the tree using recursion. The problem, however, is that it is just too ...
3
votes
1answer
647 views

Finding the total time elapsed in the union of time intervals

Given a set of time intervals, I have to find the total time elapsed in the union of the intervals. Test Cases: ...
6
votes
1answer
90 views

Find number of neighbour pairs in the input tree

My code works with small binary tree but with big ones (around 10000 nodes) it takes 15 sec to process. For small binary tree I'm always getting correct answer and it is fast. How can I make my ...
7
votes
1answer
767 views

Chopsticks game in Python

As a beginning project, I decided to code something that plays the game Chopsticks in Python 3. I'm using the Minimax algorithm, and exploring the tree using simple recursion. One of the main problems ...
3
votes
2answers
151 views

Time Limit Exceeded for build_max_heap

This problem is from HackerEarth: The Monk learned about priority queues recently and asked his teacher for an interesting problem. So his teacher came up with a simple problem. He now has an ...
1
vote
2answers
508 views

Matching lines in a CSV file with items in a dictionary

I was wondering if there was a better way of writing this... I have a CSV file (about 6640 lines). After reading through the file, the values for the DFN_Network ...
2
votes
0answers
47 views

Selecting the most recent record for each product

I have the following structure of a table: ...
2
votes
2answers
1k views

Sum of all the primes less than or equal to N

...
5
votes
2answers
365 views

Number of ways to make change for an amount

Task Write a program that, given the amount to make change for and a list of coins prints out how many different ways you can make change from the coins to STDOUT. My approach The number to make ...
3
votes
0answers
98 views

Getting contacts from phone is taking too much time

I am working on an instant chat messaging application. I am getting contacts from phone and displayed them in list view of an activity, but it is taking 25-30 seconds using the following code: 1. On ...
10
votes
2answers
626 views

Finding all contiguous sublists such that each member appears an even number of times

The program needs to find all contiguous sublists of numbers where the number of occurrences of every member in the contiguous sublist is divisible by 2. The first line of input is N (the number of ...
13
votes
3answers
3k views

Comparing two strings to see if string 2 is inside string 1

Here is what I have to do: Write a function scramble(str1,str2) that returns true if a portion of ...
5
votes
3answers
130 views

Compose valid subtractions using all digits from a set

I have created a brainteaser, which I called the "impossible problem" (see this video I made). The aim is to create a valid 3-digit subtraction which uses every digit from 1 to 9 once. Here is an ...
4
votes
1answer
201 views

Segmented Sieve of Eratosthenes in Scala

I'm trying to solve PRIME1 in SPOJ with the following Scala snippet: Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between ...
4
votes
1answer
102 views

Clojure reverse multiple times

I have a piece of Clojure code that reverses a string recursively. It is working but too slow (because I got the problem from Codewars and I cannot validate it ...
8
votes
5answers
392 views

Pizza Hut math problem #1 in Haskell

I'm currently attempting to learn Haskell after a fair history of imperative programming. When I saw the Pizza Hut Pi Day math problems, I thought the first one would be a good candidate for my ...
2
votes
1answer
535 views

Quickly find percentile with high precision

I need to find the percentile where a list of values is higher than a threshold. I am doing this in the context of optimization, so it important that the answer is precise. I am also trying to ...
3
votes
2answers
475 views

Counting numbers whose digits all go up or down

I have created a program which takes a value x and uses this value to create a power of ten value like so 10 ** x. This has ...
1
vote
1answer
299 views

Finding Kth Permutation Sequence

I have written a program to display the kth permutation sequence of a string made up of letters 'O' and 'Z' . I tried optimizing it but my code have not passed test cases due to timeout issues.Looking ...
2
votes
1answer
3k views

Finding the percentile corresponding to a threshold

I need to find which percentile of a group of numbers is over a threshold value. Is there a way that this can be speed up? My implementation is much too slow for the intended application. In case this ...
3
votes
1answer
194 views

DFS algorithm too slow

I am practicing my coding on leetcode, and my submission, although correct for small cases, is timing out for large ones. Could you please let me know how to improve my code? The question is as ...
4
votes
1answer
408 views

Time limit exceeded for java “insertion sort linked list”

I was working on LeetCode to practice myself with Java programming. I encountered a question about insertion sort a linked list. My code currently runs correctly, but it failed on an instance with ...
6
votes
3answers
517 views

Korean word segmentation using frequency heuristic

This a continuation of a previous question. I want to thank Joe Wallis for his help with increasing the readability of my code. Although the changes made by Joe Wallis did increase the speed of the ...
5
votes
1answer
185 views

How to lose plants and aggravate people

Courtesy of a few posts around here I've discovered HackerRank. Poisonous Plants is one of their challenges. Of course, skip the following if you'd like to try it yourself. Challenge: There are \$...