The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
5
votes
0answers
115 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 ...
4
votes
0answers
499 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 ...
4
votes
0answers
627 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 ...
4
votes
0answers
799 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 ...
4
votes
0answers
209 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 ...
3
votes
0answers
421 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 ...
3
votes
0answers
93 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 ...
3
votes
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 ...
3
votes
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, ...
3
votes
0answers
557 views

Find smallest subset of integers having a given sum

Write a function that meets the specifications below: ...
3
votes
0answers
541 views

Hackerearth Simple Function - Follow-up

Problem statement Let us first describe a SimpleFunction: ...
3
votes
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 ...
3
votes
0answers
984 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 ...
3
votes
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 ...
2
votes
0answers
69 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 ...
2
votes
0answers
71 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 ...
2
votes
0answers
35 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 ...
2
votes
0answers
27 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 ...
2
votes
0answers
111 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 ...
2
votes
0answers
244 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 "...
2
votes
1answer
8k 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 ...
2
votes
0answers
396 views

HackerRank university codesprint array construction

Problem statement Professor GukiZ has hobby — constructing different arrays. His best student, Nenad, gave him the following task that he just can't manage to solve: Construct an \$n\$-...
2
votes
0answers
1k views

HackerRank - Matrix Rotation

Problem statement Given a matrix (up to 300 × 300), rotate each element R steps anti-clockwise along concentric rectangular paths (R up to 109). The algorithm is rated as hard on HackerRank. On ...
2
votes
0answers
657 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: ...
2
votes
0answers
264 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}\$....
2
votes
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}$ ...
2
votes
0answers
389 views
2
votes
0answers
47 views

Selecting the most recent record for each product

I have the following structure of a table: ...
2
votes
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 ...
1
vote
0answers
60 views

Python Bubble sort

...
1
vote
0answers
52 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 ...
1
vote
0answers
405 views

Sending device data of 10k items with Parallel.ForEach

I have a deviceList of more than 10k items and want to send data by calling another method. I tried to use Parallel.Foreach but I'm not sure is this the correct ...
1
vote
0answers
115 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 ...
1
vote
0answers
81 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 ...
1
vote
0answers
192 views

SPOJ GSS1 challenge (maximum subarray sum) using Java

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]+...+...
1
vote
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 ...
1
vote
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 ...
1
vote
0answers
132 views

Determine amicable pairs within confines of Θ(n)

I had to implement a program that takes a number userNum from the user and finds all perfect numbers and pairs of amicable numbers within the range \$\lbrace 2, \...
1
vote
0answers
437 views

Hackerrank > Woman's CodeSprint 2 > stone division, Revisited ( recursive function)

Problem statement You have a pile of n stones that you want to split into multiple piles, as well as a set, S, of ...
1
vote
0answers
72 views

Extract climate variables on species range from worldclim and save into CSV

My code is currently taking too long to extract climate variables from the worldclim dataset. I would like to download the climate data from the link and find the maximum temperature over my species ...
1
vote
0answers
133 views

Getting TLE for SPOJ Bitplay challenge program

I have tried a naive way to solve this problem: Given a even number N (N ≤ 109) and an integer K, you have to find the greatest odd number M less than N such that the sum of digits in binary ...
1
vote
1answer
376 views

Find max in-order difference in array

Given an array A of integers, find the maximum of j - i subjected to the constraint of A[i] <= A[j]. If there is no solution possible, return 0. Example : A : [3 5 4 2] Output : 2 for the pair ...
0
votes
0answers
511 views

Function to sum values of most significant digit contained

ABOUT For each subsequence, look at its position in the original decimal representation of \$x\$. Let's say that the most significant digit it contained was the \$e\$-th digit, where \$e=0\$ ...
0
votes
0answers
100 views

The number having odd divisors between 2 numbers

I am trying to solve a problem from Hackerearth. I'm able to solve sample testcases but somehow when I am submitting the solution it gives time limit exceeded error or wrong output message. Problem ...
0
votes
0answers
133 views

Hackerrank All Women's Codesprint 2019: Visually Balanced Sections

Link: https://www.hackerrank.com/contests/hackerrank-all-womens-codesprint-2019/challenges/visually-balanced-sections/problem Problem Description A rack has \$n\$ horizontal compartments. The ...
0
votes
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 : ...
0
votes
0answers
223 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 ...
0
votes
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 ...
-3
votes
0answers
44 views

A problem: HackerEarth says it is TIme limit exceeded

I have written a solution to Memorise me problem on Hacker Earth but it takes a lot of memory space and time limit exceeds in the last test case. The first line of input will contain N, an integer, ...