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

816 questions
Filter by
Sorted by
Tagged with
231 views

### Calculating total maintenance costs of a car

Introduction I drive a white 2CV from home to work, and intend to keep that way until retirement. Once retired, I will sell the 2CV to buy a yacht and sail away. My home is far, far away from ...
338 views

### Solving Code Jam's Dice Straight

I'm trying to solve the Code Jam Dice Straight problem. My Python solution seems to produce the correct output for the first few test cases but then it becomes too slow. How can I possibly optimize it?...
456 views

### Variant of 2-SUM Problem using Hashtable with multi-threading

I am doing a Coursera assignment on Hashtable and my solution is taking too long to run. Here is the problem as described in the assignment: The goal of this problem is to implement a variant of ...
262 views

### Project Euler #12 (Highly divisible triangular numbers) in Python 3.x

I'm a beginner to programming and just started python, I've been trying to work through Project Euler challenges. I wrote a program to solve Project Euler #12, which asks for the smallest number of ...
208 views

### Find subsets of size K in N set

The question is: There is a set An, and it consists of integers from 1 to n. ...
137 views

### SPOJ Emoticon challenge

I tried this spoj problem and solved it using Dynamic Programming, but I was getting Time Limit Exceeded. The challenge is to count the number of occurrences of the subsequence "KEK" in each input ...
35 views

### Program that uploads and process excel files current limit is 20,000 lines

My program is called "Cleaner". What it does is that we have a "Dirty" excel file with a good number of lines in it around 20,000 - 400,000 lines. The process of cleaning the records is basically ...
106 views

### Grab data from one sheet and insert/format it into another sheet

I have code that runs and does what I want it to do with the click of the command button, however when executing, it runs very slow. The code grabs data from one sheet and inserts/formats it into ...
34 views

### Count number of registers in interval & location

Recently I asked how one could count the number of registers by the interval as answered in https://stackoverflow.com/questions/49240140/count-number-of-registers-in-interval. The solution works ...
155 views

### Counting primes in given interval

So, here is a Hackerearth question, regarding (more or less) counting the number of primes between a given pair of numbers (up to 106). Then there were 3 major options available to me: Trial ...
460 views

### Cheapest flights with at most k stops

This is the Cheapest Flights Within K Stops problem from leetcode.com: There are $n$ cities connected by $m$ flights. Each fight starts from city $u$ and arrives at $v$ with a price $w$. ...
59 views

### Substitute Excel-Workbook reference for another

I have an Excel-Workbook, where we have an sheet where we consolidate data. Basically we link to other Excel-Workbooks. I wrote the following Macro, in order to update the path and filename. We cannot ...
104 views

### Solving for <45 degree angles of a multi-vector system

I'm working on a problem from codechef.com. The goals are: Solve for whether or not the driver took a "sharp turn", meaning for some angle θ, θ > 45°. Test each point $(x_i, y_i)$ in the system ...
457 views

### Goldbach's Conjecture

I am doing an exercise on finding the nearest pair of prime numbers p₁ and p₂ such that: p₁ ≤ p₂ p₁ + p₂ = n (for 4 ≤ n ≤ 10⁷) p₁ and p₂ are primes p₂ - p₁ is minimal I think it should work ...
2k views

### Count palindrome substrings

Given a string S, count and return the number of substrings of S that are palindromes. Single length substrings are also palindromes. We just have to count the substring that are palindrome. ...
58 views

### Number of Pushes, time limit exceeding

There are N boys standing in line in order 1 to n. For each ith boy (i from 1 to N) W[i] gives his weight. A boy in line can push another boy if his weight is more than or equal to the sum of weight ...
78 views

### Listing all possible names from a phone number

In the program we have to input a number and then calculate all the possible name we can form according to the following rule: ...
994 views

### Word counter using a word list and some text files

My program works with two types of files. File 1 contains 500,000 distinct words. File set 2 contains 173 text files, each containing 500 paragraphs, that I scraped from Wikipedia. The program ...
647 views

### Filtering rows in Excel according to words, dates, and ID numbers

I have 3 columns of ID, Field, and Date (Apologies, I do not know how to format so everything is neat in 3 columns): ...
96 views

### Sum the remainders of ai%aj given an array “a”

Given an array of numbers, I am creating a table where, the cell at the intersection of row i and column j contains a number ai % aj. Numbers in the array can occur multiple times. Example: For ...
555 views

### BFS to check if path from start node to end node exists

I'm trying to solve a problem from leetcode called Jump Game and it seems to be a pretty simple graph problem where we have to find if a path exists from a start node to an end node. I personally ...
141 views

### Find the probability of picking a prime number in a range

The task is: From a sub-sequence of integers between 2 inputted numbers A and B, we need to find the probability of picking a prime number. I have written something to accomplish the task- ...
273 views

### Kattis “Chasing Subs” custom decryption challenge

I wrote a function to solve a problem in Java, but it's still too brute force, and I'd like to optimize in terms of runtime. Link to the description of the problem. The input consists of two lines: a ...
227 views

### Sorting a 2-dimensional array with counting sort

The task I'm solving is: Sort a list by its keys Print out the corresponding values on one line separated by whitespace Replace the values of the first half of the input to "-" Use Counting Sort The ...
131 views

### Solve Time Limit Exceeded for list<int> in c++

The input begins with an integer $q, 1 \leq q \leq 10^5$, the number of queries. The next $q$ lines each gives a query. A query is $\text{"a x"}, 1 \leq x \leq 10^9$ Print the result of each ...
227 views

### Project Euler #9: Finding Pythagorean triplets with a given sum

Problem statement: A Pythagorean triplet is a set of three natural numbers, A < B < C, for which, A² + B² = C². Given a number N, check if there exists any Pythagorean triplet for which A + B + ...
119 views

### Finding next greater element

This is the Daily Temperatures problem at leetcode.com: Given a list of daily temperatures, produce a list that, for each day in the input, tells you how many days you would have to wait until a ...
180 views

79 views

### Ruby Sudoku Solver without classes

I'm writing a Sudoku solver in Ruby to complete a coding challenge with the following restrictions. Failing to follow the following restrictions will result in an invalid submission: Do ...
542 views

### Sums for list of ranges (CodeFights Basic Skills)

I can solve this problem with a brute force naive solution, but need to optimize it for time. I'm not in school, but trying to learn fundamentals on my own. I know I need to store the sum of the ...
193 views

### Largest Prime Factor of Number in PHP or QBasic [closed]

I was solving the 3rd problem at Project Euler which requires me to calculate the largest prime factor of 600851475143 which I think is a really large number (more than 6 billion). QB64 At first, I ...
212 views

### Project Euler #196: Prime triplets

I did the HackerRank version of Project Euler #196 using Python 3. My code ran successfully for 6 test cases out of 20. For test 14, it showed a timeout error which is not a functionality bug but ...
311 views

### Quickest way of finding the largest integer n such that n! has length of m bits

Factstone Benchmark Amtel has announced that it will release a 128-bit computer chip by 2010, a 256-bit computer by 2020, and so on, continuing its strategy of doubling the word-size every ...
118 views

### Splitting a rectangular chocolate bar

I'm having trouble with my school homework. I have a chocolate bar that consists of either black, white or black&white (mixed) squares. I'm supposed to divide it in two groups, one that has only ...
6k views

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

I have this program to find pairs of amicable numbers in C: ...
71 views

### Leet Code :: Merge Binary Tree :: Time Complexity [closed]

Problem Statement: Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not. You need to merge them into ...
128 views

### Search for solutions to quartic diophantine equation

I wrote this code to find the variables that will satisfy the diophantine equation (i.e. a^4 + b^4 + c^4 = d^4), for all variables belong to: (0 , 430000), and it takes forever to find the answer (I ...
105 views

### Leetcode: divide without multiplication, division, and mod operator

I am new to this and would like to know some basic tips to make my coding more efficient, because on this question my code is obviously not efficient enough for the practice problem and I looked in ...
2k views

I have been doing this challenge in which I need to determine and return one's (i.e. alice) rank on a leaderboard by comparing her scores to the others'. I made ...