# 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.

50 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
0answers
114 views

### Stacking and folding machine-learning algorithm

I am trying to use the code of this guy. Written in 2013 but it is a bit obsolete on some points. Basically, the idea is to create folders from 1 dataset to train several models independently on the ...
1answer
27 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 ...
2answers
114 views

### Heights of Cats

I have an assignment to solve this problem. However, I have exceeded the time limit required, can anyone suggest where to improve my code? Cats like to sit in high places. It is not uncommon to see ...
0answers
431 views

### Make DFS Implementation faster for 8 puzzle problem in Python

I am implementing DFS algorithm for the 8 puzzle problem which works fine if the goal is reached in less than 10 iterations. But for longer number of iterations, my implementation doesn't return the ...
0answers
521 views

### Minimum number of moves to solve “game of fifteen”

I read about this game and tried to make my own algorithm to solve this. I asked it on StackOverflow for the appropriate algorithm and logic to solve this problem. With the help of answers over ...
0answers
781 views

### Finding combination of coins that can produce a given sum

This function is checking, whether it has enough money in a list called self.deviceMoney to make change. It works exactly the way I want, but only in case where ...
0answers
208 views

### Time Limit Exceeded with shortest path algorithm

The problem: SHPATH You are given a list of cities. Each direct connection between two cities has its transportation cost (an integer bigger than 0). The goal is to find the paths of ...
0answers
280 views

### Given an input string and a pattern, implement wildcard pattern matching

I have been trying to solve "Wildcard Matching" on leetcode. I know there are more "manual" ways to solve this without using the RE library. But I would like to know if passing the time limit is ...
0answers
89 views

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

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 ...
0answers
79 views

### Best path using some intermediate points, where cost is either x-axis or y-axis distance

We are given N Cartesian points $(x, y)$. Anytime we move from $i$-th point to the $j$-th, the move costs $\min\left(\left|x_i - x_j\right|, \left|y_i - y_j\right|\right)$. The problem is to ...
0answers
76 views

### SPOJ Fast Matching challenge

I wrote a solution to the MATCHING challenge on SPOJ: FJ has N (1 ≤ N ≤ 50,000) cows and M (1 ≤ M ≤ 50,000) bulls. Given a list of P (1 ≤ P ≤ 150,000) potential matches between a cow and a bull, ...
0answers
545 views

### Find smallest subset of integers having a given sum

Write a function that meets the specifications below: ...
0answers
506 views

### Hackerearth Simple Function - Follow-up

Problem statement Let us first describe a SimpleFunction: ...
0answers
2k views

### Pandas calculation speed of stock beta on many dataframes

I have many (4000+) CSVs of stock data (Date, Open, High, Low, Close) which I import into individual Pandas dataframes to perform analysis. I am new to Python and want to calculate a rolling 12month ...
0answers
908 views

### Solving the Mining algorithm from HackerRank

I was working on this problem for a few hours last night and finally came up with a brute-force solution. The task is to report the minimum work necessary (sum of weight × distance) to relocate gold ...
0answers
98 views

### Getting contacts from phone is taking too much time

I am working on an instant chat messaging application. I am getting contacts from phone and displayed them in list view of an activity, but it is taking 25-30 seconds using the following code: 1. On ...
0answers
68 views

### Bias-corrected percentile Bootstrapping Optimization

I have never posted to this forum, but was referred here. I need some help printing key iterations as well as optimizing my code for run time. If someone had some time to help/explain how to correct ...
0answers
64 views

### lowest common ancestor with square root decompostion

This is my implementation of lowest common ancestor problem,I tried to solve it using square root decomposition pre processing time : O(n) query time:O(sqrt(h)) h -> height of tree This ...
0answers
32 views

### Solving the wooden snake chain puzzle

My code tries to solve the wooden snake chain puzzle: I do so by generating all possible link configurations which are then tested. I was hoping that laziness would take care of the very many ...
0answers
26 views

### Script to report disk usage

I am trying to see how I can speed up the below script that reports disk usage. The timed find command towards the end is the problematic line that I am trying to ...
0answers
108 views

### Leetcode: divide without multiplication, division, and mod operator

I am new to this and would like to know some basic tips to make my coding more efficient, because on this question my code is obviously not efficient enough for the practice problem and I looked in ...
0answers
240 views

### Learn trie through Leetcode 212

Problem statement: Given a 2D board and a list of words from the dictionary, find all words in the board. Each word must be constructed from letters of sequentially adjacent cell, where "...
1answer
7k views

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

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 ...
0answers
642 views

### Counting numbers in an array that are divisible by any 2 numbers

While solving one question I got stuck with a time limit error. The main objective in question is to count numbers in an array $A$ that are either divisible by $P$, $Q$ or both. Input format: ...
0answers
241 views

### GSS4 - Segment Tree implementation 2

The problem is also known as GSS4. The exact detail can be seen here but I reached TLE. You are given a sequence A of N(N <= 100,000) positive integers. There sum will be less than $10^{18}$....
0answers
57 views

### Calculate and plot expected value involving summations and products

I wrote a code to calculate a series of summations and products for a maths assignment I'm doing. The equation is shown below. E(\sigma)=[1-(P(\text{$1^{st}$ rejects}) \times P(\text{$2^{nd}$ ...
0answers
386 views

...
0answers
47 views

### Selecting the most recent record for each product

I have the following structure of a table: ...
0answers
3k views

### Solution to King Kohima problem in Python

King Kohima problem: King Kohima has reserved a new exclusive street for his executive class employees where they can build their homes. He has assigned you to plan that street. You have to ...
0answers
48 views

### Graph-coloring solution using depth-first search

I'm trying to solve this question: Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them. The park consists of n ...
0answers
104 views

### Quora upvotes trends Hackerrank challenge

The following code is my solution to an old problem I found today. Input Format Line 1: Two integers, N (1 ≤ N ≤ 106) and window size K (1 ≤ K ≤ N) Line 2: N positive integers of upvote ...
0answers
31 views

...
0answers
80 views

### Ruby Sudoku Solver without classes

I'm writing a Sudoku solver in Ruby to complete a coding challenge with the following restrictions. Failing to follow the following restrictions will result in an invalid submission: Do ...
0answers
184 views

### SPOJ GSS1 challenge (maximum subarray sum) using Java

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

### Copy data for a list of stocks from all Excel files in a directory

I'm trying to do the following things. ThisWorkbook has list of stocks. By using for loop i'll select each cell. Number of rows in this sheet are 215. Create a new workbook with the name as above ...
0answers
69 views

### P5 Isothermic Map Generator From Data Points

In my earth science class at school we had a lab where we went around the campus measuring the temperature at different place and marking it on a map. Afterword we were told to color the map using ...
0answers
128 views

0answers
44 views

### Counting events that occur in some time intervals

I have a python code where I need to count the number of ids in a given range of timestamps as : ...
0answers
173 views

### Time limit exceeded on HackerRank “Username Disparity”

Here is the hackerrank question: For two strings A and B, we define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of ...
0answers
36 views

### Program that uploads and process excel files current limit is 20,000 lines

My program is called "Cleaner". What it does is that we have a "Dirty" excel file with a good number of lines in it around 20,000 - 400,000 lines. The process of cleaning the records is basically ...
1answer
94 views

### Count the maximum weight of an independent tree subset

I got an algorithm counting max weight of independent tree subset: ...