We’re rewarding the question askers & reputations are being recalculated! Read more.

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
137
votes
17answers
17k views

Disproving Euler proposition by brute force in C

I wrote a little bit of code to brute force disprove the Euler proposition that states: $$a^4 + b^4 + c^4 = d^4$$ has no solution when \$a\$, \$b\$, \$c\$, \$d\$ are positive integers. I'm no ...
23
votes
8answers
3k views

Area of the triangle generated by the hands of a clock

Problem explanation: Let’s suppose we have a clock that has an hour hand 3 units long, a minute hand 4 units long, and a second hand 5 units long. The hour hand moves once every hour, the minute hand ...
21
votes
7answers
7k views

Finding pairs of Amicable Numbers, up to 10000

I have this program to find pairs of amicable numbers in C: ...
20
votes
1answer
597 views

Remapping and interpolating 255x1024 array

I have a function that accepts a \$255\times1024\$ array and remaps it to another array in order to account for some hardware related distortion (lines that should be straight are curved by the lens). ...
19
votes
3answers
4k views

Loading military units into ships optimally, using backtracking

I solved the following problem using backtracking: We are given a list of military units, their weight and their (numerical) strength. We have a number of ships with a limited carrying capacity....
19
votes
3answers
938 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 ...
19
votes
2answers
3k views

Search a big (13 GB) Outlook PST file

I have an Outlook PST file of a pretty big size (13 GB). For some indexing purpose I needed to scan through the full PST file to get all the PR_SEARCH_KEY and then ...
18
votes
9answers
2k views

Repeatedly eliminate a substring

I'm trying to pass a programming challenge where we are to replace all instances of a substring in a string until there are none left. So an input like ...
17
votes
5answers
2k views

Flipping coins performance

This is the Flipping coins problem on CodeChef: There are \$N\$ coins kept on the table, numbered from \$0\$ to \$N - 1\$. Initially, each coin is kept tails up. You have to perform two types of ...
17
votes
2answers
2k views

Yandex programming contest: Alarms

I've tried to solve this challenge about 4 hours during the contest, but all my attempts exceeded the time limit. I tried to solve it with min-heap, but can't pass all the tests. How it can be solved ...
16
votes
4answers
2k views

Leetcode 15. 3 Sum

Problem statement Given an array S of n integers, are there elements a, ...
14
votes
5answers
5k views

Hacker Rank: Array left rotation

This code is to solve the Hacker Rank problem array left rotation. A left rotation operation on an array of size n shifts each of the array's elements 1 unit to the left. For example, if 2 left ...
14
votes
6answers
10k 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....
14
votes
4answers
1k views

Codechef: Prime Number Generator

Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate all prime numbers between two given numbers! Input The input begins with the number t ...
14
votes
2answers
3k views

O PC, why are you so slow?

In order to test some software I've written, I need to write values to a test harness with OLE for Process Control (OPC). The problem is, for a larger range of values I'm generating points for (say ...
14
votes
4answers
3k views

2-sum problem on a range in Python

Here is the problem description (from an algorithm course: https://www.coursera.org/learn/algorithm-design-analysis): The goal of this problem is to implement a variant of the 2-SUM algorithm (...
14
votes
1answer
2k views

3-Sum Problem in Python

I attempted the 3-Sum problem on Leetcode, where the problem asks to find all possible triplets of numbers in a given list such that their sum is 0. My code worked, but it exceeded the time limit for ...
13
votes
2answers
2k views

Removing neighbors in a point cloud

I have written a program to optimize a point cloud in dependency of their distances to each other. The code works very well for smaller number of points. For 1700 points it takes ca. 6 minutes. But I ...
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 ...
13
votes
3answers
1k views

Optimisation of palindrome

My program takes as first input the number of test cases, n. For the following n inputs, I output the smallest positive integer that has to be added to the input to make the input a numeric palindrome....
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 ...
12
votes
3answers
12k views

Counting permutations without repetitions for a number or a string

Can I make the following code faster with minor modifications? It times out on CodeWars website. ...
12
votes
2answers
3k views

Project Euler #10 in C++ (sum of all primes below two million)

Project Euler Problem 10 asks for the sum of all the primes below two million. I'm creating a list of primes and keep checking any new number for divisibility with only prime numbers. I thought it ...
12
votes
1answer
1k views

Looking for a way to create a particular matrix in python in a less amount of time

I want to create a matrix like this in Python: $$ \begin{pmatrix} 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 2 & 2 & 2 & 2 & 3 & 3 & 3 & 3\\ 0 & 1 &...
12
votes
4answers
1k views

Delete rows in spreadsheet where cells match some patterns

I have vba code that loops through a large number of records and deletes rows based on criteria. The issue at hand is that it takes far too long to run. I have never actually let it finish because it ...
12
votes
3answers
872 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 ...
12
votes
1answer
332 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 ...
12
votes
1answer
3k views

Hackerrank Queen's Attack II

Problem statement A queen is standing on an \$n\$x\$n\$ chessboard. The chessboard's rows are numbered from \$1\$ to \$n\$, going from bottom to top; its columns are numbered from \$1\$ to \$n\$, ...
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 ...
11
votes
9answers
38k views

Find the repeated elements in a list

You are given an array of n+2 elements. All elements of the array are in range 1 to n. All elements occur once except two numbers, which occur twice. Your task is to find the two repeating numbers. ...
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\$) ...
11
votes
4answers
9k views

Finding the first duplicate in an array

My code returns the correct answer the first duplicate is 3 (represented as int f) . I am struggling finding a more efficient way to find the first duplicate? My ...
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 ...
11
votes
3answers
859 views

Aggregate prescriptions per drug in a CSV file

I have a question that is similar in spirit to this previously asked question. Nonetheless, I can't seem to figure out a suitable solution. Input: I have CSV data that looks like (FICTIONAL ...
11
votes
3answers
1k views

Given a number, find a multiplier to make a product whose digits are increasing or decreasing

I found a problem where I have been given a set of numbers. One has to find for each number the smallest positive integer such that the product of the number and the integer gives a number whose ...
11
votes
3answers
2k views

Pigeon and grain problem: find time until all the grain is eaten

Problem: There are \$n\$ pigeons and \$m\$ grains. Pigeon \$i\$ eats a single grain every \$x_i\$ seconds. Find the time until all the grain is eaten. Input: A line with the integer \$...
11
votes
2answers
723 views

Breadth First Search to find connected primes

I've been working through the British Informatic Olympiad's 2016 Paper, and I've been struggling with some of the larger cases for question 3, specifically the larger cases on the mark scheme (the 3 ...
11
votes
1answer
1k views

Memory-Test for Soldiers

I am solving the following problem on code chef: \$N\$ Soldiers are lined up for a memory test. They are numbered from 0 to N-1 from left to right. In the test, there are \$M\$ rounds. In each ...
11
votes
1answer
242 views

Using Support Vector Machine algorithm to analyze satellite image [closed]

I am using Support Vector Machine (SVM) algorithm to perform a classification. The satellite image I am using is really big (5GB) that's why I am trying to take advantage of ...
10
votes
9answers
4k views

Find the nth prime between 1 and 1,000,000 in under 3 minutes - follow-up

Previous question: Checking for the nth prime number between 1 and 1,000,000, must compute 1,000,000th in under 3 minutes My mission is to find the nth prime number, based on user input 1-1,000,000. ...
10
votes
3answers
1k views

Binary search in C#

The challenge requires the program to receive data from the console and use binary search to find if a term is contained in a set of other terms. I've unit-tested the solution below, but according to ...
10
votes
3answers
1k views

Macro that does some kind of duplicate check

This macro pulls in two workbooks, one being a template with saved formulas already, and the other containing data with thousands of rows...I need to increase the speed because the process takes more ...
10
votes
4answers
2k views

Find the next multiple of N that is a perfect square number

Given a number \$t\$, (\$1 \leq t \leq 1000\$) that represent testcases and \$t\$ numbers \$n\$ (\$1 \leq n \leq 10^9\$). Show the next multiple of \$n\$ that is a perfect square number. ...
10
votes
5answers
568 views

Minimum perfect squares needed to sum up to a target

I'm trying to solve this problem Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n. I've come up with a solution that ...
10
votes
3answers
637 views

Calculating the number of zeroes at the end of a factorial

The code seems to work, but, I always get the "Time Limit Exceeded" error (the time limit defined is 6 seconds). I even tried reducing the number of iterations but am still running short on time. I am ...
10
votes
3answers
209 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 ...
10
votes
2answers
2k views

Lovely Lucky LAMBs

I am trying to solve this question from google's foobar. However, my code exceeds the time limit, even though when I tested it I got correct answers. How can I make my code more efficient? Lovely ...
10
votes
3answers
5k views

Finding indices 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 ...
10
votes
2answers
4k views

Checking for any character common to two strings — Go is 50× slower than Python

I decided to learn Go, knowing Python. My approach is by solving easy problems like this one: You are given two strings, A and B. Find if there is a substring that appears in both A and B. ...
10
votes
3answers
674 views

Master Locksmith

Description Master Locksmith has just finished the work of his life: a combination lock so big and complex that no one will ever open it without knowing the right combination. He's done testing ...