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
6
votes
1answer
147 views

Immediate Smaller Element Time Limit Exceeded

Immediate Smaller Element The code is working fine Code is here. For each element in the array, check whether the right adjacent element (on the next immediate position) of the array is smaller. If ...
6
votes
2answers
103 views

Program for activity selection exceeds time limit

I've been trying to solve this problem for some while and the solution I have come up with exceeds the lime limit by 1-3 ms and 2 out of 10 tests get a memory issue error. Why is that? This is the ...
6
votes
1answer
392 views

Block storage rewrites

Summary In a block storage system, new data is written in blocks. We are going to represent the flash memory as one sequential array. We have a list of block writes coming in the form of arrays of ...
6
votes
1answer
337 views

Prime Number Generator Time Limit Exceeded

PRIME1- Prime Generator The code is working fine and it's generating a prime number from M to N but the only problem is I'm getting TLE when I submit my answer. How do I optimise my code to pass the ...
6
votes
2answers
189 views

Denoise an image under extreme time pressure

I'm working on a real-time, embedded system image processing application for my group engineering capstone in undergrad. I'm receiving data at 60FPS, and have to isolate and detect the location of a ...
6
votes
3answers
517 views

Korean word segmentation using frequency heuristic

This a continuation of a previous question. I want to thank Joe Wallis for his help with increasing the readability of my code. Although the changes made by Joe Wallis did increase the speed of the ...
6
votes
2answers
140 views

A recursive program that attempts to solve an extremely large number

This is my recursive program for the following function: \$F(x) = G(x) - W(x)\$ \$G(x) = [G(x-1)+G(x-2)]^2\$ \$W(x) = [W(x-1)]^2 + [W(x-2)]^2\$ If x == 0 in either function G or function W, then ...
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. ...
6
votes
1answer
5k views

Filter Duplicate Elements in Haskell

I'm working on HackerRank to try to improve my Haskell skills along side with reading Haskell Programming from first principles. I wrote a program that works, but it seems to time out on large input ...
6
votes
1answer
364 views

“Changing Bits” challenge

Problem Statement: Let A and B be two N bit numbers (MSB to the left). You are given initial values for A and B, and you have to write a program which processes three kinds of queries: ...
6
votes
3answers
2k views

Hackers Ranking String Similarity

I am currently trying to teach myself some programming. I have started to work with Python by doing this challenge. For each test case, I need to find the sum of the self-similarities of a string ...
6
votes
2answers
166 views

Troublesome Frog (AIO Intermediate 2013) 3.x

Recently I was trying out this problem and my code got 60% of the marks, with the remaining cases returning TLEs. Bazza and Shazza do not like bugs. They wish to clear out all the bugs on their ...
6
votes
3answers
895 views

Find area of intersection between 2 squares rotated 45 degrees

Ok so I am trying this task on a Code Challenge website, but I can't figure this out to do this fast enough. Because my current solutions has ...
6
votes
1answer
847 views

Calculate angle between planes

I have written working code calculating the angle between the adjacent planes. I read subsequently from standart input: n - amount of triangles, m - amount of vertices ind[] - indices of the vertices ...
6
votes
2answers
328 views

Central Delannoy numbers

I am solving this problem on SPOJ Upper Right King (Hard): There is a king in the lower left corner of the \$ n \times n \$ chess board. The king can move one step right, one step up or one step up-...
6
votes
2answers
3k views

Efficient implementation of a Dynamic Programming challenge

I wrote the following code for a Dynamic Programming problem but the online judge gives me a 'Time Limit Exceeded' error. How can I optimize this code to make it more efficient, especially the part ...
6
votes
2answers
1k views

Python code to split csv into smaller csvs, not splitting IDs

I have Python code that splits a given large csv into smaller csvs. This large CSV has an ID column (column 1), which consecutive entries in the csv can share. The large csv might look something like ...
6
votes
3answers
779 views

Matching values from html table for updating values in pandas dataframe

This is more of an exercise for me to get use to Pandas and its dataframes. For those who didn't hear of it: Pandas is a Python package providing fast, flexible, and expressive data structures ...
6
votes
1answer
40 views

Search for strings in a list that have > 90% similarity

Explanation: I am working on String comparison in which I want to cross-compare the list of the same input string. For the same string, I am continuing the loop but if a single string will have ...
6
votes
2answers
129 views

Listing page visits for each visitor

I have some data in the following format: ...
6
votes
1answer
68 views

Undoing corrections to a big dataframe

I have 2 dataframes. The first one (900 lines) contains corrections that have been applied to a deal. The second dataframe (140,000 lines) contains the list of deals with corrected values. What I am ...
6
votes
2answers
840 views

Trie with insert, search, and startsWith methods for lowercase strings

I wrote the following prefix tree data structure for this Leet code challenge. Implement a trie with insert, search, and <...
6
votes
2answers
2k views

Finding longest common prefix

I have been trying to solve a modification of the Longest Common Prefix problem. It is defined below. Defining substring For a string P with characters P1, P2,…, Pq, let us denote by P[i, j] ...
6
votes
1answer
90 views

Find number of neighbour pairs in the input tree

My code works with small binary tree but with big ones (around 10000 nodes) it takes 15 sec to process. For small binary tree I'm always getting correct answer and it is fast. How can I make my ...
6
votes
1answer
1k views

Computing the de Bruijn sequence

I'm trying to compute de Bruijn sequences for alphabets which have a number of characters which is a power of two. So the sequence must contain every possible subsequence of length \$N\$ from \$0\$ to ...
6
votes
1answer
118 views

Finding intersting path in a graph

There is a question in a contest but it doesn't have any answer. I solve it but I get time limit for most of test case. Is it possible to improve my code or give a better approach? Question There is ...
6
votes
1answer
2k views

Down to Zero II

Problem : https://www.hackerrank.com/challenges/down-to-zero-ii You are given queries. Each query consists of a single number N. You can perform 2 operations on N in each move. If N=a*b (a!=1,b!=...
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 ...
6
votes
2answers
243 views

Count the number of inversions using Binary Indexed Tree in an array

Original Problem: HackerRank I am trying to count the number of inversions using Binary Indexed Tree in an array. I've tried to optimise my code as much as I can. However, I still got TLE for the ...
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 ...
5
votes
5answers
725 views

Project Euler 92: count sum-squared-digits chains that reach 89

A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before. For example: 44 → 32 → 13 → 10 → 1 → 1 85 → 89 →...
5
votes
4answers
523 views

Summed absolute difference of two array

Question (SAD Queries on CodeChef) The Summed Absolute Difference (SAD) of two arrays. Given arrays (1-indexed) \$P\$ and \$Q\$ of lengths \$p\$ and \$q\$. Given a collection of \$n\$ arrays ...
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 ...
5
votes
2answers
2k views

Sort characters in a Python string by frequency

I wrote a solution to the leetcode problem Sort characters by frequency and the solution passes 34/35 test cases. On the last test case, there is a "time limit exceeded" error with an input string of ...
5
votes
3answers
2k views

CodeWars kata 'Sum Of Pairs'

I need help in optimizing my code for this challenge. I think my algorithm is fine and I pass all sample tests but get took longer than 12000ms to complete error for final one. I guess there are a ...
5
votes
3answers
595 views

SPOJ solution of GRAVITY

I am solving problem GRAVITY on SPOJ. Each test case is a rectangular ASCII grid of dimensions m × n, and you have to determine ...
5
votes
3answers
115 views

For each pair of strings, eliminate the characters they have in common

In the below code there are 3 inputs. First line of input is the number of testcases for which the program will run where (1<=testcases<=10) and i is an ...
5
votes
2answers
1k views

Fastest path on a snakes and ladders board

I am not looking for a detailed review of this code as I am aware it is very inefficient. The main reason for posting this is to see if there is a better way to achieve my goal (I am certain there ...
5
votes
5answers
3k views

Finding large Fibonacci Number in Python

I'm doing Project Euler at 1000-digit Fibonacci number - Problem 25 which says The Fibonacci sequence is defined by the recurrence relation: Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1. ...
5
votes
2answers
1k views

Inti Sets: Hackerank

Here is the original question. In order to motivate his Peruvian students, a teacher includes words in the Quechua language in his math class. Today, he defined a curious set for a given ...
5
votes
3answers
69 views

Counting GUAG introns in chromosomes

I have this code that is working fine but it's taking pretty much 100% of my cpu to run and it takes around 25min. I'd really like to optimize it but don't know what parts I could improve. The main ...
5
votes
2answers
634 views

Deleting millions of rows from a MSSQL server table

This SQL query took 38 minutes to delete just 10K of rows. How can I optimize it? Index already exists for CREATEDATE from ...
5
votes
2answers
1k views

Counting the elements of one array that are less than or equal to some other numbers

I have a method which compares two array О(n2), maxes with each element in nums against <...
5
votes
1answer
2k views

C program circular array rotation

I'm trying to solve a Hackerrank problem where you perform k array[n] rotations, and at the end, ask for ...
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 ...
5
votes
2answers
188 views

Bit-based universe simulation

I am working with this problem (https://open.kattis.com/problems/whowantstoliveforever). As the problem states, my program has to determine if the universe lives or dies based on the input 0s and 1s. ...
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 ...
5
votes
4answers
4k views

Bit shifting in Python

I am trying to "decode" a file which has every byte shifted its bits. I have successfully managed to decode this by reading the file, and then byte by byte doing the following (...
5
votes
2answers
379 views

Project Euler problem 530 - GCD function is inefficient

Here is a description of Project Euler problem 530: Every divisor \$d\$ of a number \$n\$ has a complementary divisor \$n/d\$. Let \$f(n)\$ be the sum of the greatest common divisor of \$d\$ ...
5
votes
2answers
75 views

Creating nodes and edges

I'm looking for a way to optimize this piece of code in Python. all_users holds all the Twitter users and friends_ids is an ...