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.
4
votes
1answer
31 views
Computing the de Bruijn sequence
I'm trying to compute de Bruijn sequences for alphabets which have a number of characters which is a power of two. So the sequence must contain every possible subsequence of length \$N\$ from \$0\$ to ...
5
votes
2answers
113 views
Project Euler problem 530 - GCD function is inefficient
Here is a description of Project Euler problem 530:
Every divisor \$d\$ of a number \$n\$ has a complementary divisor \$n/d\$.
Let \$f(n)\$ be the sum of the greatest common divisor of \$d\$ ...
10
votes
2answers
139 views
Project Euler Problem 530: sum of sum of greatest common divisors
Here is a description of Project Euler problem 530:
Every divisor \$d\$ of a number \$n\$ has a complementary divisor \$n/d\$.
Let \$f(n)\$ be the sum of the greatest common divisor of \$d\$ ...
4
votes
1answer
68 views
Hackerrank - “Sherlock and the Beast”
I solved the problem but for two test cases, it's giving me timeout error. It's taking longer than 2 seconds on their servers. I tried using <ctime> to ...
5
votes
1answer
52 views
Calculating diagonal difference
I was trying to solve a problem concerning the difference of the diagonal sums of a matrix (using C99):
...
10
votes
3answers
99 views
Project Euler Problem 10. Sum of all primes < 2mil
I'm new to coding so I can't create complex code yet. I do as much as I can with fors and ifs, since while I know a bit about ...
8
votes
2answers
236 views
Finding indexes of numbers that sum to a target
I've taken this algorithm question, which is to find the indexes of any two numbers in an array that sum to a given number. It is quite a simple problem to solve. But it is the execution time of my ...
4
votes
1answer
507 views
Deleting millions of rows from a MSSQL server table
This SQL query took 38 minutes to delete just 10K of rows. How can I optimize it?
Index already exists for CREATEDATE from ...
6
votes
1answer
108 views
“Changing Bits” challenge
Problem Statement:
Let A and B be two N bit numbers (MSB to the left). You are given initial values for A and B, and you have to write a program which processes three kinds of queries:
...
3
votes
1answer
68 views
Scanning multiple huge files in Python (follow-up)
I'm trying to implement an algorithm able to search for multiple keys through ten huge files in Python (16 million of rows each one). I've got a sorted file with 62 million of keys, and I'm trying to ...
9
votes
1answer
405 views
Scanning multiple huge files in Python
I'm trying to implement an algorithm able to search for multiple keys through ten huge files in Python (16 million of rows each one). I've got a sorted file with 62 million of keys, and I'm trying to ...
6
votes
2answers
105 views
A recursive program that attempts to solve an extremely large number
This is my recursive program for the following function:
\$F(x) = G(x) - W(x)\$
\$G(x) = [G(x-1)+G(x-2)]^2\$
\$W(x) = [W(x-1)]^2 + [W(x-2)]^2\$
If x == 0 in either function G or function W, then ...
1
vote
2answers
95 views
Calculating the energy of a signal
I have a program to read signal data from 120 files in a folder and performing the energy of the signal.
It works correctly, but execution time is more than 20 mins, so there may be a problem with ...
3
votes
1answer
35 views
Finding the largest not-necessarily contiguous alternating binary string after inverting any sub-string from a given string
I'm having problems solving this problem within the time limit.
Alternative Thinking
http://codeforces.com/contest/603/problem/A
Kevin has just recevied his disappointing results on the USA ...
10
votes
3answers
307 views
Optimization on Sieve of Eratosthenes using vector<bool>
I am solving this prime generator problem from SPOJ:
Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given ...
5
votes
1answer
89 views
Processing weather station data using idw - Follow Up
New Approach
My previous question may have had a little too much going on and I realized I could simplify the problem by constructing the data a bit differently thanks to @Gentian Kasa . Previously, ...
10
votes
1answer
99 views
Counting paths in an n-dimensional grid that stay within the boundaries
Problem Statement
You are situated in an N dimensional grid at position (x1, x2, …, xN).
The dimensions of the grid are (D1, D2, …, DN). In one step, you can
walk one step ahead or behind in ...
8
votes
1answer
169 views
Programming Challenge from Kattis: Apparatus
I am trying to solve apparatus problem, paraphrased below.
There is an apparatus with n on/off switches with a one-to-one correspondence to n lights (but with an unknown permutation).
We have ...
4
votes
2answers
163 views
Finding longest phrase algorithm
I have this task to find the longest identical phrase which appears in 2 given files. With small files (~500KB each) it works just fine, ~10 secs to finish. But with larger files (~5MB each) it took ...
2
votes
1answer
129 views
DbGeography search query
I have a situation in which I need to get the closest road to a DbGeography point.
This takes 5 - 8 seconds to run in some cases.
I have a ...
4
votes
1answer
335 views
Processing data for five weather stations
Problem
The main idea is to build some fine scale weather data using inverse distance weighting (idw) from the 5 closest stations of the observed station. If the ...
2
votes
1answer
94 views
BFS for modified shortest path
Given K descriptions for bus line paths that exists to lead students between N campuses. What is the minimum cost that a student will have to goes from campus 1 to campus N ?
The itinerary of ...
2
votes
2answers
64 views
Block Art - IEEEXtreme 9.0
I attempted this problem from the ieeextreme, and I got timeout for just over 40% of the cases. Now that the competition is over, I was wondering what could be improved.
The problem is as follows:
...
5
votes
3answers
464 views
Project Euler 92: Square digit chains
A number chain is created by continuously adding the square of the
digits in a number to form a new number until it has been seen before.
For example,
44 → 32 → 13 → 10 → 1 → 1
85 ...
3
votes
1answer
79 views
Count Acute, Right and Obtuse triangles from n side lengths
EDIT : The Code after changes suggested by @vnp. CODE
Problem Statement: We have N sticks. The size of the ith stick is Ai. We want to know the number of different types of triangles created with ...
4
votes
1answer
153 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 ...
4
votes
2answers
246 views
My 15 puzzle solver is too slow
It takes my code over 700 seconds to solve simple puzzle:
2 7 11 5
13 0 9 4
14 1 8 6
10 3 12 15
My function ...
2
votes
1answer
60 views
Shortest path from U to V using at most k nodes
I'm trying to solve a problem that asks for a shortest path between two cities with at most k nodes.
The first line of input has the number of test cases. On the second line 3 integers are given, ...
4
votes
2answers
369 views
Find the closest number to each given number
I have a program which works but it is a bit too slow with big numbers.
nbBlocs contains the size of the array, it can be up to 20000 and I enter the value inside ...
2
votes
2answers
109 views
Gluing pieces of scrambled text (challenge on CodeEval)
I'm trying to solve this challenge on CodeEval. Quoting:
For example, you can put pieces together and get the original text:
evil pl
vil pla
il plan
The answer is ‘evil plan’.
Your ...
6
votes
1answer
51 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 ...
5
votes
3answers
255 views
Finding nearest power of 2
I have the following simple program which calculates and returns the nearest power of 2 of a given number. Because I use increments and decrements to find the closest power, this takes a very long ...
7
votes
1answer
190 views
A more optimized way of finding prime factors
I've solved Project Euler #3, but solving the same in Hacker Rank which has time constraint of < 4 seconds doesn't work. I've tried using the square root solution for speeding up but it fails.
...
1
vote
1answer
41 views
Approximately matching strings to elements in an array
I have two datasets:
A list containing about 4200 string elements
A list containing about 119,000 string elements
I'm taking each element from list 1 and looping through each element in list 2 ...
4
votes
2answers
239 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 ...
5
votes
4answers
472 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
45 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 ...
7
votes
3answers
210 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
221 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 ...
9
votes
5answers
725 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
178 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 ...
2
votes
1answer
83 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
136 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
...
16
votes
3answers
660 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
374 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
127 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, ...
4
votes
1answer
115 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 ...
5
votes
2answers
590 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
68 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 ...
3
votes
1answer
196 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 ...