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
3k views

Performing several integer division operations on an array

Program: Given an array A of size N. Given Q operations, each operation contains an integer D. In each operation you have to divide all the elements of the array by D. For example, for ...
7
votes
1answer
302 views

Java WordLadder Program

I wrote a program that calculates the minimum number of rungs of a "word ladder" between a starting word and an ending word. The function minlinks() takes in 3 ...
2
votes
2answers
2k views

Bubble sort a list of integers for a number of iterations

I wrote a program for this problem, but it stopped because it took too much time. Any tips? The Problem: Bubble sort is the simplest algorithm for elements sorting. At each iteration we sequentially ...
2
votes
1answer
3k views

Number of interesting numbers between two given numbers

Please have a look into this problem: Little Dipu is a small kid and like all the other kids, he likes to play, but he plays with numbers (he is extraordinary you know). Nowadays Dipu has some ...
5
votes
1answer
97 views

“Laser treatment” SPOJ challenge

I am trying to solve this problem on SPOJ Brazil. I'm trying to approach the problem with a series of logical conditions and my code looks like this and it works perfectly. ...
4
votes
2answers
95 views

Moving chips between cells

Challenge: You are given a line of N cells with positive integers written in them. Initially a chip is placed on the leftmost cell. Each time it can be moved in any direction (to the left or to the ...
3
votes
1answer
501 views

Grid walk problem and solving it recursively

On CodeEval, there's a Grid Walk challenge: There is a monkey which can walk around on a planar grid. The monkey can move one space at a time left, right, up or down. That is, from (x, y) the ...
0
votes
2answers
231 views

Fast sums of power algorithm

This code reaches time limit on 1 test case, solving this challenge. The approach that I'm using is from the book Algorithms Functional Programming Approach, which is a backtracking depth searching ...
2
votes
1answer
3k views

Optimizing Diwali Lights problem in C

I was trying to solve the Diwali Lights challenge on HackerRank. Problem Statement On the eve of Diwali, Hari is decorating his house with a serial light bulb set. The serial light bulb set ...
2
votes
1answer
317 views

Time Limit Exceeded for CodeChef Easy problem - STRQ (Chef and Strings)

I was working through a codechef easy problem here. I've got to a solution, but it only passes the Subtask #1. For the other two subtasks, it shows TLE (Time Limit Exceeded - which is 1 second). <...
0
votes
2answers
673 views

Uva Online Judge problem 100, 3n + 1

I am having a tough time submitting this code to UVa Online judge and having it pass. I keep getting the message - Your program used more CPU time than what is allowed for this problem. That means ...
4
votes
3answers
4k views

Finding the next palindrome code

I have been trying recently to develop a code finding the next palindrome from a certain number. For example, if the input is 800, the output should be 808, as 808 being the next palindrome from 800. ...
3
votes
1answer
1k views

HackerEarth Crazy kangaroo challenge

I want to find the lowest hop count from source to destination. The challenge, in summary: The first line contains the number of test cases T, 1 ≤ T ≤ 100000. The next T lines each contains three ...
6
votes
1answer
6k views

Divide all elements in the column of a sparse matrix

Using Python Scipy, I am trying to divide all numbers in all columns of a sparse matrix (400K × 500K, density 0.0005), by the sum of the squares of all numbers in a column. If a column is ...
2
votes
1answer
3k views

“Team formation” challenge

I'm trying to solve this problem but am getting a timeout. Can someone help me to improve? ...
20
votes
1answer
616 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). ...
3
votes
2answers
385 views

Counting the proportion of vowels in substrings

I'm looking for an algorithm to make my code faster and better for big strings. Problem link Let the simple prettiness of a string be the count of vowels (I, E, A, O, U, Y) divided by the length of ...
4
votes
2answers
710 views

Hardcoding matrix multiplication

I was doing a problem, SPOJ: FLIB. My code was running slow (getting Time Limit Exceeded error) when I was using Code1. However, my code accepted within the required time limit when I hardcoded the ...
6
votes
1answer
18k views

XOR of a list of a numbers

In preparing a solution for the CodeChef "Will India Win" challenge, I am trying to find out the xor of list of numbers. The first line of input contains the number of test cases, 1 ≤ T ≤ 106. ...
4
votes
2answers
304 views

Efficient way of finding perfect squares

I was trying to solve a problem which needed you to count the number of perfect squares in the given range: ...
4
votes
2answers
1k views

Timus Online Judge Problem 1001 - “Reverse Root”

The problem statement can be found here. Description (short): Input The input stream contains a set of integer numbers \$A_i\$ (\$0 \le A_i \le 10^{18}\$). The numbers are separated by any number ...
6
votes
6answers
7k views

Project Euler #10 — Summation of primes takes forever

I have resolved the Problem presented in Project Euler #10: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. But this code takes too ...
2
votes
2answers
530 views

Time limit exceeded for Sherlock and Queries Hackerrank challenge

Here is my C solution for Sherlock and Queries @ Hackerrank. Watson gives to Sherlock an array: \$A_1, A_2, ..., A_N\$. He also gives to Sherlock two other arrays: \$B_1, B_2, ..., B_M\$ and \$...
7
votes
2answers
1k views

Mastermind code taking hours to calculate

I'm trying to implement Knuth's Five-guess Mastermind algorithm in my own version of Mastermind, but when running step 6 it takes my code hours to actually run through everything to get the neccesary ...
2
votes
1answer
176 views

“Can you answer these queries I” challenge

I have tried to solve the following problem on SPOJ.com: You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ) A query is ...
6
votes
1answer
229 views

Evaluating Fibonacci-sequence-based recurrence relation (SPOJ Flibonakki)

I have a function fib2 which returning two values as Tuple but I want to print the product of tuples returned by function fib2. I am new to Haskell so please ...
4
votes
1answer
822 views

Optimizing a dynamic programming solution for “Oil Well”

I'm trying to solve the Oil Well problem on Hackerrank using dynamic programming and it works. However, it times out for some of the test cases. I wanted to know how this program can be improved so ...
2
votes
2answers
1k views

Timeouts when calculating stock ratings using LINQ

I'm getting a lot of timeouts with the following code and I'm running this method around 10,000 times so I need to figure out how I can optimize this so the timeouts will stop. I am getting timeout ...
1
vote
2answers
205 views

Sum of all numbers whose remainder and quotient are the same

This prints out the sum of the numbers that have same remainder and quotient according to the input number. It's an online judge problem, and it currently throws a time-out since it's taking too long. ...
0
votes
1answer
385 views

Uniquely digitized 5-digit multiples

This is a programming problem: Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divided by ...
1
vote
2answers
63 views

Check divisibility of each line in a large dataset

I have solved this assignment in online coding community, and it has run successfully. But it's showing 12.09s of execution. How could this be optimized ? The purpose of this problem is to verify ...
6
votes
4answers
9k views

Summing Divisors

Definition: A proper divisor of a natural number is the divisor that is strictly less than the number. e.g. number 20 has 5 proper divisors: 1, 2, 4, 5, 10, and the divisor summation is: 1 + ...
6
votes
5answers
11k views

Length of the longest sequence of repeating characters

I have been going through some CodingBat exercises and I came across this problem. "Given a string, return the length of the largest "block" in the string. A block is a run of adjacent chars that are ...
3
votes
2answers
171 views

Finding string roots

This is the following Python code that I have coded for an algorithmic problem online. For each line of input, the goal is to find the greatest number of repeating blocks into which the string can be ...
5
votes
2answers
385 views

Triangle number with 500 divisors

It should work but my comp can't compute it in time. It is Project Euler problem 12. Just a small bit of advice would be nice. Only at this a short time so I probably just haven't learned a good way ...
3
votes
1answer
493 views

Time limit exceeded for SPOJ problem “Prime Generator”

Input The input begins with the number \$t\$ of test cases in a single line (\$t \le 10\$). In each of the next \$t\$ lines there are two numbers \$m\$ and \$n\$ (\$1 \le m \le n \le 1000000000\$,...
5
votes
3answers
3k views

Calculate highest prime factor very slow

Sometimes when I write a Python 3.x script with too many nested loops and some big values it just takes too long to give the answer. How can I optimize my code so that it runs faster, or where should ...
6
votes
4answers
1k views

Sum of digits in a^b

I'm trying to calculate a problem which requires sum of digits in \$a^b\$, where \$0 \le a \le 9\$ and \$0 \le b \le 4000\$. I have seen various other posts similar to this, but I haven't acquired ...
4
votes
2answers
82 views

Slowly working word counter

I have a problem where, given N terms, the task is to find the k most frequent terms from given N terms. My code is correct, but I have a time limit 10 seconds and my code doesn't pass. Constraints: ...
1
vote
1answer
101 views

MinCostMaxFlow implementation is not fast enough

I'm trying to solve this problem: A root tree is a directed acyclic graph that contains one node (root), from which there is exactly one path to any other node. A root tree is binary if each ...
0
votes
4answers
91 views

Finding powers of multiple array pairs

I'm doing a challenge on TalentBuddy that requires you to find the powers of multiple array pairs. Since I got the solution right, but not fast enough, I decided I'd ask for help here. ...
4
votes
1answer
3k views

Finding a word ladder using Breadth First Search

This is a LeetCode problem called Word Ladder: Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, where only one letter can ...
0
votes
3answers
177 views

Splitting many data files by quintile

The program below is about finding the values below the percentage and splitting them into five different output files. This works great for small input data files. But when I am trying to run it for ...
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 ...
10
votes
9answers
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. ...
4
votes
1answer
348 views

CodeEval Sequence Transformation

I've been working on this challenge for a week: There are two sequences. The first sequence consists of digits "0" and "1", the second one consists of letters "A" and "B". The challenge is to ...
6
votes
2answers
862 views

Project Euler #48 in C++

This question is similar to Project Euler #48 but constraints are different: $$N < 2000000$$ Just in case the link is unavailable, here is the problem statement: We've to print $$\left( \sum_{...
3
votes
2answers
214 views

“Cool Guys” CodeChef challenge

I was trying to solve a question on CodeChef. My code works perfectly fine in my IDE (Visual Studio here) but when I submit my code at CodeChef, it says "Time Limit Exceeded". What the code does: ...
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....
-1
votes
2answers
365 views

Fastest way to find maximum deviation

I acknowledge that this exact question was asked here. I was working on the same problem from the same website. I had the same question and consulted the above as a reference, however with respect ...