# 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.

1,001 questions
Filter by
Sorted by
Tagged with
18k 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 ...
11k views

### Finding pairs of Amicable Numbers, up to 10000

I have this program to find pairs of amicable numbers in C: ...
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 ...
4k views

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....
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 ...
676 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). ...
1k 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 ...
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 ...
3k 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 ...
2k views

### Leetcode 15. 3 Sum

Problem statement Given an array S of n integers, are there elements a, ...
10k 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 ...
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 ...
17k 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....
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 ...
2k 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 of test cases ...
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 (...
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 ...
4k 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 ...
3k 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. ...
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 ...
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....
5k 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 ...
5k 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$, ...
18k 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. ...
4k 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 ...
12k 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 ...
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 &...
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 ...
914 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 ...
404 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 ...
163 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 ...
66k 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. ...
4k views

### HackerRank Implement Queue using two stacks Solution

Challenge Problem Statement - Implement a Queue using two Stacks I implemented dequeue() in $O(1)$ at the cost of enqueue() ...
815 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$) ...
9k 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 ...
826 views

### Finding reversed word pairs

I wrote this code to find opposites of words (i.e., words backwards). Input is a list of words. If this list contains a word + its opposite, then it should form a pair. The output should be a list of ...
2k views

### A faster way to compute the largest prime factor

I am self-learning js and came across this problem(#3) from the Euler Project The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? ...
1k 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 ...
2k 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 ...
2k views

764 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 ...
2k 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 ...
5k views

### Google FooBar "Prepare The Bunnies Escape"

I'm currently working through the google FooBar challenge, and I'm on the third level, in which I have to find the distance between the top left and bottom right points on a grid. The grid is filled ...
292 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 ...
5k 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. ...
2k 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 ...