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
2
votes
2answers
2k 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
414 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 minimum cost ...
3
votes
1answer
1k 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
166 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
862 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
222 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
129 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
1k 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
160 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
1k 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
2k 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
470 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
324 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
798 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
94 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
1k 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
187 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
717 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
49 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
524 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
107 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
748 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
4k 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
147 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
221 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
113 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
423 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
638 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
531 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
328 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
4k 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
229 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
441 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
587 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
197 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 \$...
3
votes
1answer
121 views

Redirecting arriving customers to the nearest empty queue

I have a task to make a checkout line controller. First it receives, as input, an amount of checkouts and commands. Then commands that are C for coming and L for leaving, and after those the number of ...
1
vote
1answer
148 views

Code to analyse text get stuck if too much data

I've made the following VBA script to analyse text recurrence in a huge batch of descriptions. For a small part of the batch the code run smoothly, but when I include everything it tends to loose ...
2
votes
1answer
100 views

Performance of the String searching algorithm

I am trying to solve a string matching question mentioned here. I recently learned the Knuth–Morris–Pratt algorithm and tried to implement it to solve this question. But I am getting a TLE for this ...
2
votes
0answers
3k views

Solution to King Kohima problem in Python

King Kohima problem: King Kohima has reserved a new exclusive street for his executive class employees where they can build their homes. He has assigned you to plan that street. You have to ...
2
votes
2answers
635 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 ...
5
votes
1answer
4k views

Hacker rank Jesse and Cookies

I am trying to solve a problem on Hacker Rank and the question is as follows: Jesse loves cookies. He wants the sweetness of all his cookies to be greater than value \$K\$. To do this, Jesse ...
4
votes
3answers
4k views

Sort a stack of numbers in ascending order only using push

I have a stack of numbers ranging from 1 to 1 million representing a pile of numbered DVDs. Given the stack in random order I am to sort the stack by only taking an element from the stack and push it ...
7
votes
2answers
54 views

Creating a list of new areas for patches of conserved land within a watershed

I'm writing code to create a list of new areas for patches of conserved land within a watershed based on the current size distribution of conserved land patches that are in the watershed now. I'm ...
14
votes
6answers
15k views

Counting numbers with specific digits

The challenge: Suppose you are inhabitant of a planet where 1, 7, and 9 are lucky digits. A lucky number for you is a number that contains only your lucky digits in it. For ex: 1, 79, 911, 9917 etc....
4
votes
2answers
512 views

Find all integers between m and n whose sum of squared divisors is itself a square

Divisors of 42 are : 1, 2, 3, 6, 7, 14, 21, 42. These divisors squared are: 1, 4, 9, 36, 49, 196, 441, 1764. The sum of the squared divisors is 2500 which is 50 * 50, a square! Given two ...
3
votes
2answers
617 views

Hackerrank challenge - Dictionaries and Maps in Erlang

This question is really similar to an existing one in Ruby. So the task is also the same: Day 8: Dictionaries and Maps! The problem is that on Hackerrank my solution only passes the first and last ...

1
13 14
15
16 17
19