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
1
vote
1answer
46 views

Sort and Delete duplicate image files

I'm trying to make a console application to sort and delete duplicate image files. I have a folder with about 20000 images which take up roughly 70GB of space. I wrote the following script and it ...
1
vote
1answer
54 views

Inserting data into MySQL

My code currently doesn't insert data into MySQL fast enough. However I don't know how to measure the current speed. ...
2
votes
2answers
88 views

Can I further optimize this solution for HackerRank's “Making Candies”?

My C++ solution for HackerRank's "Making Candies" problem, reproduced below, is as optimized as I can make it and appears similar to what others say are optimal solutions. However, six of ...
2
votes
1answer
46 views

Leetcode 3 sum code optimisation

I was working on 3sum problem on leetcode Question Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the ...
0
votes
5answers
79 views

Determine whether a magazine contains the words needed for a ransom note

This is a website Question on Hackrrank called Hash Tables: Ransom Note: Given the words in the magazine and the words in the ransom note, print "Yes" if we can replicate the ransom note ...
-2
votes
2answers
71 views

Hackerrank: Absolute Permutation - How do I make this code more efficient

The problem is basically this: Return the permutation of the set of the first n natural numbers which satisfies the following property: |pos(i) - i| = k ∀ i ∈ (1,n) where pos(i) is the ith number in ...
1
vote
4answers
311 views

“Digit Queries” CSES Solution giving TLE

I really need a more accurate way to size inf_string. This code works but gets exponentially more inefficient the bigger max(queries) is, and therefore just can't hold up to the gargantuan numbers ...
2
votes
1answer
52 views

Performance issue in python- network creation based on the Euclidean distance with nested for loops is too slow

I want to create a network in which the links are formed based on a similarity metric defined as the Euclidean distance between the nodes. The distance is calculated using socio-demographic features ...
3
votes
1answer
82 views

Optimizing Dijkstra on grid Python (Microsoft Interview)

Given a square grid of size N, each cell of which contains integer cost which represents a cost to traverse through that cell, we need to find a path from top left cell to bottom right cell by which ...
3
votes
2answers
104 views

How to speed up the code for LeetCode “Container with most water” task?

I'm trying to solve the LeetCode question where you need to find out the area of the container with the most water. I have created the solution that seems to work in my testing but it fails for being ...
2
votes
2answers
57 views

CSES - Number Spiral - Java TLE

My java code for CSES Introductory problem Number Spiral gives TLE for large inputs, like Input : 100000 170550340 943050741 121998376 943430501 689913499 770079066 586095107 933655238 … (First line/...
-1
votes
1answer
108 views

Generating permutations fast

I run into a performance bottleneck in a program. I have to generate all permutations for a given sequence with size up to n=11. My code: ...
4
votes
2answers
128 views
2
votes
1answer
123 views

Counting binary substrings

The exercise i am working on requires me to read a binary sequence stored in a text file. The objective is to find the occurrences of all subsequences of length between a and b (their values are given ...
11
votes
5answers
639 views

Finding reversed word pairs

I wrote this code to find opposites of words (i.e., words backwards). Input is a list of words. If this list contains a word + its opposite, then it should form a pair. The output should be a list of ...
1
vote
1answer
58 views

calculate tree height (arbitrary tree) - python

Given an array as input, we have to calculate the tree height. For example, input [4, -1, 4, 1, 1] means that there are 5 nodes with numbers from 0 to 4, node 0 is a child of node 4, node 1 is the ...
2
votes
0answers
35 views

Calculating edges of a social network

I am working on an open Chess data-set (~15500 rows after cleaning), and I create nodes and edges. But the way I create the edges takes a bit of time. A sample of my nodes tibble: player 1 bougris ...
3
votes
2answers
1k views

Determine the longest segment of integers within an inclusive range that doesn't contain a bad number using Python

I am new to python. Got a question in Hackerrank. Given an Array of bad numbers and a range of integers, how can I determine the longest segment of integers within that inclusive range that doesn't ...
1
vote
1answer
53 views

The Next Palindrome - CodeChef

This is codechef beginner problem. How I can make it efficient, It is taking 2.09 sec while time limit is 2.0764 secs. Problem is: For a given positive integer K of not more than 1000000 digits, write ...
0
votes
2answers
66 views

Find the smallest triangular number with more than 500 factors

I wrote a program about triangular numbers, which are derived from the sum of natural numbers one after the other. For example, the third triangular number is equal to: 1 + 2 + 3 = 6. I want to find ...
2
votes
1answer
62 views

Count the different positions reached in a cycle of permutations

I have come across a problem on cyclic permutations. It is about swapping numbers around. It starts out with input N < 100,000 which makes the first N natural numbers as orders: 1 2 3 ... N-1 N ...
-3
votes
1answer
175 views

HackerRank | Roads and Libraries - Code Optimization

Major Edit: I wish people threw in a comment regarding what they are expecting instead of downvoting this question. I am quite appreciative of constructive feedback. I know it is only 3 people out of ...
3
votes
2answers
83 views

Finding minimum steps required to traverse from source to terminal

Hello everyone this is my first post here so please do critique my post if there's anything. I have made a program intended to pass a programming challenge on open.kattis.com, here. It should do as ...
2
votes
1answer
77 views

Geeks for Geeks: Trapping Rain Water Problem - time limit exceeded

Problem Statement: Given an array arr[] of N non-negative integers representing the height of blocks. If width of each block is 1, compute how much water can be trapped between the blocks during the ...
2
votes
2answers
128 views

Determine whether a number and its square are both the sum of two squares

Code gets timed out and needs to be simplified. To ensure that n = sum of squares , To determine if n^2 = sum of squares , I need to input 4 integers : 5881, 2048, 2670, 3482 ...
3
votes
3answers
114 views

Summation of large inputs

Assume we are given \$ n \$ natural numbers, \$a_{1}, a_{2}, \dots, a_{n} \$ and we are supposed to calculate the following summation: \$ \sum_{i = 1}^{n}\sum_{j = 1}^{n} \left\lfloor \dfrac{a_{i}}{a_{...
1
vote
2answers
173 views

Determine whether bitwise-OR of sub-array is odd

Problem: Given an array A of N integers, you will be asked Q queries. Each query consists of two integers L and R. For each query, find whether bitwise OR of all the array elements between indices L ...
2
votes
5answers
102 views

Revised: Counting subnumbers divisible by a given prime

Assume we are given a number and a prime p. The goal is to count all subnumbers of number ...
0
votes
0answers
28 views

Calculating total payment value between date periods with different pay frequencies

For this problem I originally wrote some VBA code which worked perfectly. I've since been tasked with integrating the results it produces with the spreadsheets data model so thought a PowerQuery would ...
2
votes
1answer
80 views

Dijkstra's algorithm in graph (Python)

I need some help with the graph and Dijkstra's algorithm in Python 3. I tested this code (look below) at one site and it says to me that the code took too long. Can anybody suggest how to solve that? ...
2
votes
1answer
101 views

Find minimal modulo-sum of pairs from two lists

Recently I appeared for an job challenge organised on HackerEarth. Question: There are two teams T1 and T2. Power of each player is represented in array. The rules of game are as follow. There are ...
0
votes
0answers
70 views

Performance issue “not enough memory” Macro vba Excel - Parsing data

I have built some code that should parse the data according to a unique value and then create a new Worksheet for each unique value. My initial table has 10 Columns and around 25K rows. The code works ...
-4
votes
1answer
580 views

Removing chocolates 1 & 3 at a time

A box contains a number of chocolates that can only be removed 1 at a time or 3 at a a time. How many ways can the box be emptied? The answer can be very large so return it modulo of 10^9+7 ...
4
votes
0answers
66 views

C++ - Longest Common Subsequence

Link to the Problem Here is my code to compute the length of the longest common subsequence of two integer arrays arr[] and brr[]...
-1
votes
1answer
56 views

Find pairs of primes that sum to specified even number

Below code is for Given an even number (greater than 2), return two prime numbers whose sum will be equal to the given number my task to reach the lowest time complexity I tried it differently, but I ...
0
votes
0answers
57 views

HMRO - Help the Military Recruitment Office

I am solving this problem on SPOJ but I am getting Time Limit Exceeded Error. https://www.spoj.com/problems/HMRO/ At the end of year 2004, the regional agencies of the Polish Military Recruitment ...
0
votes
2answers
99 views

CodeWars kata Fusc function running too long, but very fast locally

I have a solution to this CodeWars challenge that's being rejected as "too slow". Basically, write public static BigInteger Fusc(BigInteger n) given: ...
3
votes
1answer
101 views

LeetCode - Weekly Contest 213 - Kth Smallest Instructions

Hi I participated in Leetcode weekly contest 213 and am facing issue with submission for below question Kth Smallest Instructions Bob is standing at cell (0, 0), and he wants to reach destination: (...
1
vote
0answers
57 views

Astar algorithm exceeds time limit

I have code that reduces an array until all remaining elements are the same. It takes a first line which contains an integer n, the number of elements in the array, and a second line which contains ...
6
votes
1answer
70 views

Graph: Depth First Search (N citizens with pairs of friends)

I have solved problem 10608 on UVA Online Judge using Python 3.5.1. My solution works, but it takes too long to run when the online judge evaluates it. Problem There is a town with N citizens. It is ...
6
votes
1answer
115 views

01 Matrix is too slow when solved using DFS

I tried solving Leetcode 01 Matrix problem. It is running too slow when solved using DFS approach. Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell. The distance ...
5
votes
1answer
54 views

Twitter contact scraper with Tweepy & Django

I created a project for academic purposes that works on Twitter data. It should: Get all friends and follows of the user Store them in MongoDB Display them in a table I'm using django + plain HTML, ...
2
votes
3answers
84 views

Efficiently calculate the value of an arithmetic sequence

I need to calculate the value for the following function: $$f(n) = -1 + 2 - 3 + ... + -1^n$$ The time limit to calculate a given value of \$n\$ is less than 1 second. My approach does not meet that ...
2
votes
1answer
72 views

HackerRank - Binary tree to compute the Nth power of natural numbers that sum up to X

I'm trying to solve this challenge on HackerRank. In short, given x and n, I have to determine how many ways I can pick numbers ...
3
votes
1answer
37 views

Count number of square integers in a given range of ints (faster function?)

The function below passes most test cases: ...
2
votes
0answers
913 views

Better performance in solution for the Dole Out Cadbury challenge

Dole Out Cadbury Problem Description You are a teacher in reputed school. During Celebration Day you were assigned a task to distribute Cadbury such that maximum children get the chocolate. You have ...
4
votes
0answers
152 views

Cross-Entropy Minimization - Extreme Code Performance

I'm working on a multivariate cross-entropy minimization model (for more details about it, see this paper, pp. 32-33). It's purpose is to adjust a prior multivariate distribution (in this case, a ...
3
votes
1answer
139 views

Prime factorisation in java

I came across this question in a coding contest (Java-restricted) and I got TLE. I am unable to provide the link of the question as the contest is closed now. Can I know how can I optimise this? Four ...
3
votes
0answers
75 views

Count unique subsequences

I came across this question in a coding competition (Java-restricted) and I got a time-length-exceeded. I am unable to provide a link as the contest is closed now. Can I know how can I optimise this? ...
-2
votes
1answer
121 views

Programming challenge - report fraudulent banking activity times out

How can I optimise this code there is time out error Program Challenge: HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount ...

1
2 3 4 5
20