# time-limit-exceeded's questions - English 1answer

648 time-limit-exceeded questions.

### MySQL select between MAX-n1 AND MAX-n2 [on hold]

0 answers, 16 views php sql mysql time-limit-exceeded database
I need to select data between 2 values from a table by using MAX because each SID has different VID. My code: ...

### Transforming tabular view of data in an Excel sheet into a vertical view

3 answers, 152 views vba excel time-limit-exceeded
I have the following code that works correctly on small data-sets, but times out and crashes on large data sets. The goal of this code is to take a tabular view of data on one sheet and transform it ...

### 3 Codewars: “Twice linear” is running too long

I am doing one kata on codewars: Consider a sequence u where u is defined as follows: The number u(0) = 1 is the first one in u. For each x in u, then y = 2 * x + 1 and z = 3 * x + 1 must be ...

### 3 Finding numbers with given gcd and lcm [on hold]

3 answers, 112 views c++ time-limit-exceeded
I am solving a question in which we are given the LCM and HCF and two numbers 'a' and 'b', our task is to find the pairs of numbers between a and b [inclusive] whose HCF is the given HCF and LCM is ...

### 2 Compare two Excel workbooks, and create a new sheet containing the differences

1 answers, 1.927 views vba excel time-limit-exceeded
I have code that scans and compares two Excel workbooks, and then pastes all of the differences between the two into a new sheet. My code is working properly - the only problem is when the Excel ...

### 3 Swift solution to Leetcode “Longest Substring Without Repeating Characters”

From LeetCode medium 3. Longest Substring Without Repeating Characters: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", ...

I have solved a spoj question CLASS LEADER. For each test case there are n students and a paper will be given to student m and now the game starts, the student m will pass the paper by o positions ...

### 9 Using bisect to flip coins

I am trying to solve this problem on Codechef, which has a list of \$N\$ coins, all initially tails-up, and a list of \$Q\$ commands. There are two possible commands, ...

### 3 Bovine Shuffle using a queue (USACO Dec 2017 Silver)

I am working on the "Bovine Shuffle" problem from the December 2017 USA Computing Olympiad, and have got it to work for every test case beside two. When I run these two cases on my own computer, they ...

1 answers, 73 views c# time-limit-exceeded web-scraping http
I wrote a class that downloads the HTML of a page from the internet. This class also manages redirects. This works well but I'm not very satisfied about time management for slower servers. In fact, if ...

### 6 Maximum absolute difference of array elements

I am trying to solve a question from array section: You are given an array of N integers, A1, A2 ,…, AN. Return maximum value of f(i, j) for all 1 ≤ i, j ≤ N. f(i, j) is defined as |A[i] -...

### 4 Split a given number so that their sum adds to another given number

Task You are given a string S containing only decimal digits ('0' through '9') and a number N. Your task is to insert an arbitrary number (including zero) of plus signs '+' into S in order to ...

### 13 Removing neighbors in a point cloud

I have written a program to optimize a point cloud in dependency of their distances to each other. The code works very well for smaller number of points. For 1700 points it takes ca. 6 minutes. But I ...

### 1 Method to return statistics from a collection with O(1) time and space

I have a DelayQueue, and the goal is to collect statistical information from the collection in O(1) time and space from ...

### 7 “Ease the Array” challenge

2 answers, 96 views c array time-limit-exceeded
I'm working on this challenge: Given an array of integers of size N. Assume ‘0’ as invalid number and all other as valid number. Write a program that modifies the array in such a way that if next ...

### 4 FirstDuplicate Finder

I read the solution to this question, which seems to be the same target. My solution is (I'm sure) not the quickest, but some test case is apparently taking longer than 4s. I did a test case with 10,...

### 3 Searching for the location of a sub-image within an image

0 answers, 32 views python time-limit-exceeded image numpy
I have a number of images that were cropped and their backgrounds removed. I've tried to write a function that will search the original unmodified image for the cropped image so that I can restore the ...

### Maximum number of unique integers

I'm given N integers. I need to find the maximum number of unique integers among all the possible contiguous subarrays of size M. ...

### DFS shortest path Prepare the Bunnies Escape Time limit exceeded

I've exceeded the time limit for my challenge at this point, so I was curious what further optimizations I could have made to my code, as it was exceeding the execution time limit allowed. ...

### -1 For every integer in an array, find the nearest greater integer both before and after it

1 answers, 65 views java time-limit-exceeded complexity
The given code gives correct output but exceeds the time limit and I have no idea how to optimize it. I know it is of \$O(n^2)\$ complexity but I am not able to get anywhere near to optimizing it. ...

### 2 Finding all possible paths between two points in a grid using recursion

I'm trying to find all possible paths made of 0 from bottom left to top right, only by moving either up or to the right. The input file contains a grid of characters, where ...

### 4 Hackerrank challenge - Apple and Orange

The problem I am trying to solve is this. Apples fall at various offsets relative to an apple tree at position a, and oranges fall at various given offsets relative to an orange tree at position b. ...

### 3 SPOJ Emoticon challenge

I tried this spoj problem and solved it using Dynamic Programming, but I was getting Time Limit Exceeded. The challenge is to count the number of occurrences of the subsequence "KEK" in each input ...

### 1 Python function to find all integers between two numbers whose sum of squared divisors is a perfect square

Divisors of 42 are : 1, 2, 3, 6, 7, 14, 21, 42. These divisors squared are: 1, 4, 9, 36, 49, 196, 441, 1764. The sum of the squared divisors is 2500 which is 50 * 50, a square! Given two integers ...

### 4 Compare Strings

You have been given two strings, A and B (of length N each) and Q queries. The strings contain only 0s and/or 1s. For every query, you are given an index i. You have to update the value at ...

### 2 Finding the maximum GCD of all pairs

The code below is for Hackerrank competition. Seems that it works correctly but performs very slowly and because of it can't pass some tests. The task is to find the maximum GCD of all possible pairs ...

### 1 Number of Pushes, time limit exceeding

1 answers, 58 views java time-limit-exceeded
There are N boys standing in line in order 1 to n. For each ith boy (i from 1 to N) W[i] gives his weight. A boy in line can push another boy if his weight is more than or equal to the sum of weight ...

### Removing entries with duplicate columns from large .vcf files

2 answers, 104 views python time-limit-exceeded csv
First of all, please note that the input (.vcf) file is very large (>60 GB). So I am reading the .vcf files line by line, but since I have to check for duplicate of two columns present in the input ...

### Getting Time limit exceeded for array updation problem which takes a lot of time to even just read input

0 answers, 54 views java array time-limit-exceeded

### 4 Find a cyclic peptide with a given non-ideal spectrum

For a course I need to build a peptide from scratch that matches the given spectrum. So I start with the amino acids that are in the given spectrum and filter those out that do not have the right ...

### 3 2D array inquiries

I am trying to solve a problem as described below: You are given an input of a n*m forest. You have to answer a group of inquiries. Your task is to return the number of trees for every ...

### 7 Python solution to Code Jam's 'Rounding Error'

The "Rounding Error" problem of Round 1B of Google Code Jam 2018 is as follows: Problem To finally settle the age-old question of which programming language is the best, you are asking a total ...

### 4 Python softmatcher using difflib impracticably slow

I have a softmatch function (below) that takes a donor list and a new entry and looks to see if the given donor already exists. The data is not exact, so I have to use a softmatch to determine ...

### 10 Finding the first duplicate in an array

4 answers, 1.537 views c# array time-limit-exceeded
My code returns the correct answer the first duplicate is 3 (represented as int f) . I am struggling finding a more efficient way to find the first duplicate? My ...

### 5 Finding black cluster size distribution for square grid at different probabilities of black elements (averaged over a certain number of iterations)

3 answers, 146 views performance c time-limit-exceeded matrix
Context: I had asked a related question on Stack Overflow. On receiving several helpful hints from the commentators there, I could successfully implement averaging of the size distribution over a ...

### 4 My attempt at Dijkstra's Algorithm in Python 3

I am practicing my coding at HackerRank. The exact problem statement can be found here, but to summarize, it is finding the distances of the shortest path from a starting node to every other node in a ...

### 4 Outputting every second char in half string

My algorithm works but it is too slow. I have to ask for help with improving this algorithm because the website which checks this, kicks me for too slow execution. What should I improve here ? ...

### 5 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: INPUT2 1 10 1 5...

### 7 Tower made of buckets - speeding up alghoritm

I need to speed up my algorithm. It is about finding height of tower. Tower is build from buckets. Each bucket has height and radius (1 <= height,radius <= 1000). Variable ...

### 2 Count number of registers in interval & location

1 answers, 30 views python time-limit-exceeded pandas
Recently I asked how one could count the number of registers by the interval as answered in https://stackoverflow.com/questions/49240140/count-number-of-registers-in-interval. The solution works ...

### 3 Project Euler #549: Divisibility of factorials

This is the problem: Calculate $$\sum_{i=2}^{10^8} s(i)$$ where \$s(n)\$ is the smallest \$m\$ such that \$n\$ divides \$m!\$. Quite mathematical, I've found a better way than brute ...

### 2 Longest Common Prefix of string

Can anyone help me remove TLE (time limit exceeded) from this? Given integer n and array of string of length n. In each query (q of them) we are given l and r and we need to find LCP in this ...

### 5 Calculating total maintenance costs of a car

Introduction I drive a white 2CV from home to work, and intend to keep that way until retirement. Once retired, I will sell the 2CV to buy a yacht and sail away. My home is far, far away from ...

### 5 Solving Code Jam's Dice Straight

I'm trying to solve the Code Jam Dice Straight problem. My Python solution seems to produce the correct output for the first few test cases but then it becomes too slow. How can I possibly optimize it?...

### 4 Variant of 2-SUM Problem using Hashtable with multi-threading

I am doing a Coursera assignment on Hashtable and my solution is taking too long to run. Here is the problem as described in the assignment: The goal of this problem is to implement a variant of ...

### 2 GSS1 SPOJ problem Time Limit Exceeding

The problem is presented here as follows: You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A query is defined as follows: Query(x,y) = Max { a[i]+a[i+1]+...+...

### 2 Sums for list of ranges (CodeFights Basic Skills)

I can solve this problem with a brute force naive solution, but need to optimize it for time. I'm not in school, but trying to learn fundamentals on my own. I know I need to store the sum of the ...

### Project Euler #12 (Highly divisible triangular numbers) in Python 3.x

I'm a beginner to programming and just started python, I've been trying to work through Project Euler challenges. I wrote a program to solve Project Euler #12, which asks for the smallest number of ...

### 1 Find subsets of size K in N set

The question is: There is a set An, and it consists of integers from 1 to n. ...

### 1 Grab data from one sheet and insert/format it into another sheet

2 answers, 100 views beginner vba excel time-limit-exceeded
I have code that runs and does what I want it to do with the click of the command button, however when executing, it runs very slow. The code grabs data from one sheet and inserts/formats it into ...