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.
2
votes
1answer
73 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
61 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
38 views
1
vote
2answers
55 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
95 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 ...
3
votes
0answers
33 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
0answers
29 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 ...
3
votes
2answers
95 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. ...
3
votes
4answers
360 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 ...
1
vote
1answer
39 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
54 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 ...
-2
votes
3answers
60 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.
...
1
vote
1answer
68 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 ...
1
vote
2answers
35 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 ...
-1
votes
0answers
54 views
SPOJ prime generator problem in Python 3
I am trying to solve an SPOJ problem using Python 3: print all prime numbers in a given range (as large as 109).
...
-4
votes
0answers
33 views
Printing numbers to a given number n and calculating the sum and count as well [closed]
This prints numbers to a given number n and calculating the sum and count as well, but my program is giving "time limit exceeded." Please suggest ways to reduce the complexity.
...
1
vote
3answers
69 views
3n+1 problem rejected by uva judge: time limit exceeded
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 ...
3
votes
2answers
136 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:
...
2
votes
1answer
56 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", ...
1
vote
0answers
36 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
61 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 ...
2
votes
1answer
58 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:
...
7
votes
1answer
123 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
32 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
50 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 ...
3
votes
0answers
32 views
2
votes
2answers
288 views
4
votes
2answers
51 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
50 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 ...
9
votes
2answers
109 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 ...
5
votes
3answers
99 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
48 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 ...
3
votes
1answer
53 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 ...
9
votes
5answers
243 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
39 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 ...
4
votes
2answers
73 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
52 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 ...
8
votes
0answers
228 views
Decompose polarimetric SAR covariance matrices in MATLAB
I want to apply the following code on 3 images of the sizes 676×718, 1430×1440, and 5576×9444, but the code is too slow even for the 676×718 image.
...
1
vote
1answer
46 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
72 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
329 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
77 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
99 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
78 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
73 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
67 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 ...
0
votes
0answers
464 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 ...
1
vote
2answers
110 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 ...
4
votes
1answer
260 views
Hacker rank Jesse and Cookies
I am trying to solve a problem in 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
2answers
148 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 ...