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
3
votes
2answers
423 views

2D array inquiries

I am trying to solve a problem as described below: You are given an input of a n*m forest. You have to answer a group of inquiries. Your task is to return the number of trees for every ...
4
votes
1answer
166 views

Find a cyclic peptide with a given non-ideal spectrum

For a course I need to build a peptide from scratch that matches the given spectrum. So I start with the amino acids that are in the given spectrum and filter those out that do not have the right ...
11
votes
4answers
8k 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 ...
4
votes
2answers
462 views

Outputting every second char in half string

My algorithm works but it is too slow. I have to ask for help with improving this algorithm because the website which checks this, kicks me for too slow execution. What should I improve here ? ...
7
votes
2answers
484 views

Python solution to Code Jam's 'Rounding Error'

The "Rounding Error" problem of Round 1B of Google Code Jam 2018 is as follows: Problem To finally settle the age-old question of which programming language is the best, you are asking a total ...
8
votes
1answer
172 views

Compute the height of a tower made of buckets

I need to speed up my algorithm. It is about finding the height of a tower. The tower is built from buckets. Each bucket has height and radius (1 <= height,radius <= 1000). Variable ...
5
votes
3answers
154 views

Finding black cluster size distribution for square grid at different probabilities of black elements (averaged over a certain number of iterations)

Context: I had asked a related question on Stack Overflow. On receiving several helpful hints from the commentators there, I could successfully implement averaging of the size distribution over a ...
5
votes
3answers
137 views

Outputting prime numbers in given ranges

I coded an algorithm which shows prime numbers in the ranges provided by the user. The first line states the number of test cases. Example: INPUT 2 1 10 1 5 ...
0
votes
2answers
245 views

Removing entries with duplicate columns from large .vcf files

First of all, please note that the input (.vcf) file is very large (>60 GB). So I am reading the .vcf files line by line, but since I have to check for duplicate of two columns present in the input ...
2
votes
1answer
226 views

Longest Common Prefix of string

Can anyone help me remove TLE (time limit exceeded) from this? Given integer n and array of string of length n. In each query (q of them) we are given l and r and we need to find LCP in this ...
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
345 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
483 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
275 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
228 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
138 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
36 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
157 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
481 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
60 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
108 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
458 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
3k 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
59 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
79 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
1k 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
677 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
101 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
582 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
143 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
274 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
229 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
135 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
234 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
126 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
185 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
288 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
2k 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
196 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
341 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
190 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
279 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
593 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
80 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
563 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
201 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 ...