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
5
votes
3answers
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 ...
4
votes
1answer
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?...
4
votes
2answers
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 ...
0
votes
3answers
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 ...
1
vote
2answers
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. ...
3
votes
3answers
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 ...
0
votes
0answers
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 ...
1
vote
2answers
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 ...
2
votes
1answer
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 ...
3
votes
1answer
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 ...
7
votes
1answer
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\$. ...
1
vote
3answers
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 ...
3
votes
4answers
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 ...
5
votes
1answer
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 ...
1
vote
2answers
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. ...
1
vote
1answer
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 ...
0
votes
1answer
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: ...
2
votes
2answers
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 ...
2
votes
3answers
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): ...
3
votes
1answer
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 ...
3
votes
1answer
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 ...
2
votes
1answer
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- ...
2
votes
1answer
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 ...
3
votes
1answer
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 ...
-4
votes
3answers
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 ...
2
votes
2answers
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 + ...
1
vote
2answers
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 ...
-1
votes
1answer
180 views

Project Euler Problem #23 (non-abundant sums) [closed]

Project Euler Problem 23 A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of \$28\$ would be \$1 + 2 ...
8
votes
1answer
287 views

Calculating the Average Minimum Length of Random Numbers From 0 - 1 that Adds up to Greater Than 1

My Computer Science teacher gave us a task to calculate the average after one billion trials. His exact assignment was this: Consider generating a sequence of random numbers on the interval [0, 1) ...
3
votes
4answers
1k views

Rearranging an array such that positive and negative elements are at alternate positions

We are given an array in which we have equal number of positive and negative elements. We have to rearrange this array such that all positive and negative elements are at alternate positions and ...
5
votes
2answers
187 views

Counting adjacent swaps to sort an array with 3 different values

This is the Kindergarten Excursion problem from kattis.com: The kindergarten teachers had finally managed to get all the kids in a line for the walk to the bus station and the weekly excursion. ...
2
votes
1answer
287 views

SPOJ - Alphacode, using dynamic programming

I am currently trying out a programming problem, SPOJ Alphacode, that involves dynamic programming. In an encoding system where A=1, B=2, …, Z=26, a message 25114 ...
4
votes
1answer
180 views

C++ Grid gravity simulation opzimization (Kattis Falling Apples)

I have a solution for the Kattis Falling Apples problem (link). The input is a grid of R rows (up to 50000) by C columns (up to 10). At each timestep, apples (indicated by ...
5
votes
2answers
257 views

HackerRank - Non-Divisible Subset

In this problem we are asked: Given a set, S, of n distinct integers, print the size of a maximal subset, S', of where the sum of any two numbers in it is not evenly divisible by k. Code My ...
0
votes
2answers
582 views

Checking if all possible combinations of any two array elements in an array contains 0-9 atleast once

I am coding for an online platform. The code is working on some test cases but is getting a Time limit exceeded. What are the ways to make my code more efficient? Input ...
10
votes
1answer
162 views

Using bisect to flip coins

I am trying to solve this problem on Codechef, which has a list of \$N\$ coins, all initially tails-up, and a list of \$Q\$ commands. There are two possible commands, ...
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 ...
1
vote
0answers
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 ...
2
votes
1answer
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 ...
0
votes
1answer
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 ...
4
votes
2answers
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 ...
3
votes
2answers
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 ...
7
votes
3answers
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 ...
20
votes
7answers
6k views

Finding pairs of Amicable Numbers, up to 10000

I have this program to find pairs of amicable numbers in C: ...
-2
votes
1answer
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 ...
3
votes
2answers
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 ...
2
votes
0answers
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 ...
8
votes
2answers
2k views

HackerRank leaderboard challenge

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 ...
13
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 ...
8
votes
2answers
186 views

Find two integers with the largest sum within a budget (breaking ties by smallest difference)

The algorithm finds a number pair that is as close to budget as possible, and if there are more pairs with same value, the pair with the least difference shall be given out. My algorithm works ...