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
0answers
9 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
40 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
112 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
105 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
168 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
93 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
23 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
56 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
93 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
57 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 ...
-3
votes
1answer
259 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
52 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[]...
0
votes
1answer
54 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 ...
1
vote
0answers
42 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/ Here is my code on Ideone with its input and output https://ideone.com/h1RAiS anyway ...
0
votes
2answers
81 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
91 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
54 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
67 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
96 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
51 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
79 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
69 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
901 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
150 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
130 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
72 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
114 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 ...
7
votes
4answers
358 views

Finding the first pair of prime numbers that have some specified difference

I tried printing the first pair of prime number in between a list of numbers with a particular difference. But my run time is still too high (for large range of numbers). I want to reduce the run time ...
3
votes
1answer
51 views

Finding the lowest perfect square that can be added to a number to make another perfect square

The code below returns the smallest perfect square that can be added to a number n to result in a perfect square. It works perfectly fine but I need it to run ...
7
votes
5answers
2k views

Enhanced Hashmap - Add a number to all keys/values

I had the below problem in a coding test and I got 28/30 tests passes and 2 failed due to a time-out. Problem You have created a programming language and now you have decided to add ...
7
votes
1answer
72 views

“Jedi's riddle” challenge

The challenge can be found here. In short we have a recursive function, and we need to find when \$z_i\$ is equal to one. $$ \begin{align} z_1 &= 1\\ z_i &= z_{i-1} * a\ \%\ n\\ \...
7
votes
2answers
188 views

Minimize sum of array by applying specific operation on x carefully chosen elements

This code works, and solves the problem, but doesn't satisfy some time requirements, especially when the 'nums' array can have a length of over 1000. How can this be optimized? Just reference: This ...
-4
votes
1answer
49 views

Time limit exceeds in this simple program [closed]

Link to problem: https://www.codechef.com/JUNE20B/problems/EVENM Iam trying to solve a simple problem challenge, but getting TLE. I had a different approach earlier, so tried this, again with no ...
1
vote
2answers
64 views

Recursive brute-force approach to maximum points you can obtain from cards

I came across this question on Leetcode. The question description is as follows: There are several cards arranged in a row, and each card has an associated number of points. The points are given in ...
1
vote
1answer
46 views

Extracting emails from log files

I have huge number of text files, each several hundred MB in size. Unfortunately, they are not all fully standardized in any one format. Plus there is a lot of legacy in here, and a lot of junk and ...
2
votes
1answer
142 views

Count number of previous elements greater than its element at present index

Suppose I have a vector containing n elements. I want to find out the number of previous elements greater than its element at present index i. I want to find ...
0
votes
0answers
34 views

How do I quickly look for parents containing their own code as child?

I have tree-like data that is constructed of Parent codes that contain Child codes which may act as parents themselves, depending on if they're marked as "SA". This data is present in an Excel sheet ...
-2
votes
1answer
74 views

How to work in linear time with DFS

I tried a Hackerrank problem and it gives me a successful message, it works fine for Hackerrank criteria. The member states of the UN are planning to send 2 people to the moon. They want them to be ...
4
votes
1answer
222 views

Leetcode three sum in Javascript

I was doing 3sum question 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 sum ...
4
votes
3answers
123 views

How can I optimize my code that uses nested for loops?

I am working to solve a problem where I need to determine if a Point lies on a line connecting two other Points. For example, ...
2
votes
0answers
41 views

HackerRank's Challenging Palindromes solution times out for certain tests

I am trying to solve the Challenging Palindromes problem from HackerRank. The code that I have got so far fails only for large inputs due to timeout, every other test it passes successfully. The ...
2
votes
1answer
98 views

Binary Search implementation: HackerRank - Climbing the Leaderboard

My code passes 11 out of 12 test cases. I was wondering where I can improve my code. NOTE: This code needs performance improvement, as it is working for most of the cases. To mu knowledge it would ...
2
votes
1answer
115 views

Calculate your total happiness, which depends on the integers in the given sets [closed]

I am a beginner in programming. And I am learning python as my first language. I went on to do some challenges on HackerRank and stumbled upon this problem. The problem goes like this: There is an ...
1
vote
1answer
174 views

Maximal Char Requests in a String

I have been trying to deal with this problem set, and I have figured out how to solve it as well. But there is one problem that is ...
3
votes
2answers
90 views

Which products should be purchased with the given amount of money: Hackerrank?

I am writing code for the challenge given here . Below the text: Each time Sunny and Johnny take a trip to the Ice Cream Parlor, they pool their money to buy ice cream. On any given day, the ...
5
votes
1answer
829 views

What should I do to reduce run time of my code?

This is a URI online judge problem (problem no: 1973). Link : https://www.urionlinejudge.com.br/judge/en/problems/view/1973 After buying many adjacent farms at the west region of Santa Catarina, ...
3
votes
1answer
111 views

Checking which polygon a set of coordinates lie inside

I have a massive set of latitude, longitude pairs. I also have a list of GeoJson formatted locations. I want to find out which location each pair of coordinates lies in. I have some code to do this, ...
1
vote
0answers
33 views

Why is my function timing out when run with a larger data set?

I am working on a Code Kata ...
1
vote
1answer
45 views

Get average post score of TOP 10 tags on StackOverflow using Stack Exchange Data Explorer

I want to use the Stack exchange data explorer in order to display some basic information about the top tags. The query should print the number of questions and answers, the average number of answers ...

1
2 3 4 5
19