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
10
votes
2answers
4k views

Checking for any character common to two strings — Go is 50× slower than Python

I decided to learn Go, knowing Python. My approach is by solving easy problems like this one: You are given two strings, A and B. Find if there is a substring that appears in both A and B. ...
0
votes
1answer
128 views

Finding the maximum of an array to solve a rope-burning puzzle

I am trying to get the maximum value out of this array. There is a long rope of length totalLength at its each unit length some ropes are tied pointing in upper ...
3
votes
2answers
188 views

CodeChef- Chef and Strange Formula

For positive integer x let define function F(x) = 1 * (1! + x) + 2 * (2! + x) + .. + x * (x! + x). "k!" means factorial: k! = 1 * 2 * .. * k Chef wants to calculate F(p1) + F(p2) + ... + F(...
2
votes
1answer
437 views

SPOJ problem - The last digit of a number to a power

Here is the problem statement: Given integers \$a\$ (\$0 \le a \le 20\$) and \$b\$ (\$0 \le b \le 2,147,483,000\$), where \$a\$ and \$b\$ are not both 0, find the last digit of \$a^b\$. ...
3
votes
2answers
7k views

Processing buy and sell orders

My code is too slow, it does the desired, but not in \$O(\log n)\$ or faster. Explanation of the auction system: For simplicity we will assume that all orders are for a single unit of the traded ...
6
votes
2answers
37k views

Printing the n'th prime numbers

This is an online problem. The challenge is to print the kth prime number, for each k given in the input (1 ≤ k ≤ 15000). The first line of input indicates the number of inputs on the subsequent N ...
10
votes
4answers
2k 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. ...
2
votes
1answer
393 views

Summing the Product of Array-member combinations

Find the sum of product of all numbers in first array with all the numbers in second array. Input Format 1st line contains 2 space separated integers N and M. 2nd line contains N space separated ...
2
votes
1answer
134 views

Vitaly & Pie Programming challenge

I've been trying to solve this problem on Codeforces: Challenge description: After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. ...
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
271 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
2k 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
93 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
92 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
410 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
224 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
2k 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
289 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
656 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. ...
2
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 ...
7
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
2k 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
593 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
352 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
677 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
16k 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
303 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 ...
5
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
524 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
174 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
225 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
776 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
199 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
364 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
8k 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 + ...
4
votes
4answers
10k 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
168 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
375 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
470 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
100 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
85 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. ...