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

1,011 questions
Filter by
Sorted by
Tagged with
1 vote
51 views

### Infix calculator programming challenge Kattis.com

I'm working on this C++ coding problem: Input is a sequence of up to commands, one per line, ending at end of file. Each command is a definition, a calculation, or a clear. All tokens within a ...
1 vote
35 views

### R code to calculate coef

Can you help me think of some way to reduce the computational time of a code that generates a certain value, which in this case I call coef, which will depend on <...
• 121
683 views

### Find non-overlapping pairs of elements in a list whose difference is less than some given threshold

I have the following task: Let us have a list (denoted by L, and for simplicity, the elements come from the interval [0,1]). We are given a parameter (denoted by C), and we want to find as many pairs ...
• 153
666 views

### Python analog clock with turtle - runs slow

I made a python analog clock program with turtle. The problem is, it takes about 1.4 seconds to loop, so it only moves the second hand every 1.4 seconds. Its probably cuz my computer is slow... ...
• 191
1 vote
74 views

### Closest Pair of Points - Optimizing Code for big sets of points

I'm trying to create an algorithm that finds the closest pair of points (2D) within a set of points. I'm using a divide and conquer method which is explained here Closest Pair of Points Algorithm. ...
• 11
1 vote
79 views

### Find next biggest palindrome

I have written a program for the SPOJ PALIN problem: A positive integer is called a palindrome if its[decimal representation is the same]from left to right and from right to left. For a given ...
23 views

### Pull pictures from folders on Google Drive and add them to a Sheet

I have code that I have been using for 2 years and it was working perfectly until recently. It started to give a timeout warning a couple of weeks ago and now it's not really running anymore. The code ...
49 views

### Finding all "triplets" of an integer array but in a more optimal manner

I'm practicing the following problem Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. ...
• 31
96 views

### Array rotation in C++

I am completely new to data structures and algorithms. I tried this problem on hackerank. I got the desired output but my code wasn't efficient enough to execute in the given time limit. How can I ...
• 89
74 views

### Highly divisible triangular number

Highly divisible triangular number, my solution My solution of challenge from Project Euler takes too much time to execute. Although on lower numbers it works fine. Anyone could look up to my code and ...
• 31
187 views

### Kattis challenge, processing string with special characters and conditions

I'm new to programming challenges and I'm attempting the following Kattis challenge Sim. This problem is an extension of another Kattis problem - backspace. In that problem, every time we see a ...
64 views

### Optimizing my code for Project Euler+ problem #1 on HackerRank

The Project Euler contest is ongoing on HackerRank and the first problem is finding out the sum of multiples of 3 and 5 below a certain number N. Two of the hidden test cases fail when I execute my ...
207 views

### HackerRank: Sam and substrings | How can dynamic programming be used in my code?

Given a number as a string, no leading zeros, determine the sum of all integer values of substrings of the string. Given an integer as a string, sum all of its substrings cast as integers. As the ...
50 views

### Hackerrank's New Year Chaos problem (find minimum number of swaps to reach a permutation)

I am trying to solve the problem to Hacker Rank's New Year chaos problem. I have come up with a not so elegant solution. This is failing to adhere to the timing constraints of Hackerrank My approach ...
158 views

### 567: Permutation in String

So I've been working on this for a few days actually. I implemented a solution to the LeetCode problem: 567. Permutation in String The Problem Given two strings s1(queryStr) and s2(sourceStr), return ...
• 121
27 views

### Efficient algorithm to track all the direct parents and transitive parents(parents of parents and grand parents) in a directed acyclic graph

I am preparing for online coding assessment, where I have come across a question to write an algorithm to find the list of direct parents and transitive parents for each vertex in a directed acyclic ...
• 41
1 vote
32 views

### CSES Number Spiral Java TLE

I am trying to solve the CSES Number spiral problem https://cses.fi/problemset/task/1071/ However, I get the TLE problem. How can make my code more efficient? ...
• 11
1 vote
71 views

### Minimum Window Substring in Swift exceeds LeetCode runtime check

This is a popular question on LeetCode: 76. Minimum Window Substring Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in ...
• 129
1 vote
107 views

### HackerRank - Climbing the Leaderboard: I don't understand why my code is exceeding the time limit

Climbing the Leaderboard An arcade game player wants to climb to the top of the leaderboard and track their ranking. The game uses Dense Ranking, so its leaderboard works like this: The player with ...
1 vote
41 views

### RE: Find maximum value of recursively-defined "fusc" function

Continued from the previous post - a brute-force approach to calculating all the vectors from 0 to n. I've come up with yet another solution, after I've realized that the vector takes up too much ...
499 views

### Find maximum value of recursively-defined "fusc" function

I've been trying this question from SPOJ, which asks for the user to enter a number n, and they will receive a maximum fusc value that lies in between 0 to ...
398 views

### Counting swaps in a sequence sorting algorithm

I have been working on this question, https://open.kattis.com/problems/sequences. You are given a sequence, in the form of a string with characters ‘0’, ‘1’, and ‘?’ only. Suppose there are n ‘?’s. ...
128 views

### Leetcode First Unique Character in a String code optimisation

I was working on First Unique Character in a String Question Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1. Example 1: ...
• 179
1 vote
102 views

### Target Sum array using Dynamic Programming

I'm learning Dynamic Programming and trying to solve this Target Sum array problem. I've to find an array of integers that sums to a given target sum using the integers of given input array. I've used ...
• 247
1 vote
74 views

### Finding longest palindromic substring in a string (gives TLE on leetcode)

I'm solving the Longest Palindromic Substring problem on LeetCode. And here's my final submission: ...
• 113
127 views

### Leetcode 662. Maximum Width of Binary Tree Javascript FlatMap attempt - Time Limit Exceeded

Problem Statement: Given the root of a binary tree, return the maximum width of the given tree. The maximum width of a tree is the maximum width among all levels. The width of one level is defined as ...
418 views

### Recursive solution of ordered Coin Combinations II (CSES)

Question Link Consider a money system consisting of n coins. Each coin has a positive integer value. Your task is to calculate the number of distinct ordered ways you can produce a money sum x using ...
• 131
89 views

I am doing this problem: You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version ...
• 277
78 views

### GCD of n numbers

According to an online judge, the limit has been exceeded. Could someone help me optimize my solution for the Greatest Common Divisor of n numbers: ...
• 21
100 views

### HackInScience exercise: Sequence Mining

I am working on a practice problem found here: https://www.hackinscience.org/exercises/sequence-mining Overview Sequence mining is useful for analyzing list of events when order matters. It's used ...
• 43
61 views

### Climbing the leaderboard (Hacker Rank) via binary search

I am trying to solve the Climbing the leaderboard problem on Hacker Rank. My code passes all the test cases except Test Cases 6 to 9, which I assume are using large data sets. I'm using binary search ...
• 13
156 views

### Leetcode (443) String Compression

This is the question I tried Leetcode: String Compression Given an array of characters chars, compress it using the following algorithm: Begin with an empty string s. For each group of consecutive ...
1 vote
156 views

### Leetcode 377. Combination Sum IV Javascript Memoization attempt

Problem Statement ...
117 views

### How to speed up the VBA scraping process

I want to scrape 25000 addresses using Column A cell values as search strings. I'm using the following code, it is working fine but it's too slow to extract 25000 results. Is there any way to speed up ...
• 21
51 views

### UPDATEIT SPOJ problem using Segment tree

UPDATEIT on SPOJ: UPDATEIT - Update the array ! #bitmasks You have an array containing n elements initially all 0. You need to do a number of update operations on it. In each update you specify l, r ...
• 101
1 vote
64 views

### A function to find all the primes between two numbers whose reverse is also a prime and doesn't include palindrome, in JS

I am trying to solve a challenge in which I have to write a function that takes in two numbers as arguments and returns an array containing numbers between them which are prime and their reverse is ...
• 113
104 views

### Shortest route algo terribly slow

First post. I posted this on stack as well but somebody suggested I post it here too/instead. I wrote a shortest-path script for a Unity game project, and while it works, it gets so slow when applied ...
• 21
1k views

### How to do modulo thing fast (less execution time)

I was solving a question on a coding website and this website has a limit for execution time of code. My code takes 1.01 sec but the limit is 1 sec. I am unable to find any changes in my code that ...
• 123
1k views

### Find the number of trailing zeros in factorial

I am trying to find the "Number of trailing zeros of N!" (N factorial). In the python code I am trying to find the factorial first and then the number of trailing zeros. However, I am ...
1 vote
88 views

### Maximum Profit in Job Scheduling - Performance Issue

I implemented the Maximum Profit in Job Scheduling algorithm in JavaScript, but I'm having performance issue. The problem: We have n jobs, where every job is scheduled to be done from startTime[i] to ...
40 views

### Attempting to solve minimum window substring problem using Python 3.8

Hello programming gurus/reviewers, I attempted to solve the Minimum Window Substring (Leetcode 76) problem using Python 3. My solution involved using Counters and backtracking. On submission, the ...
294 views

### Calculate sum of a substring

I try to solve some old Codeforces questions. The problem is; Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up q ...
1 vote
64 views

### Non equi self join with basic python libraries

I'm trying to do a non equi self join with basic python libraries on a table that has 1.7 millions rows and 4 variables. the data look like this: ...
• 11
1 vote
180 views

I am trying to solve Google Foobar challenge prepare-the-bunnies-escape using my own approach, instead of BFS. I attempt to solve two ends of the maze and try to ...
326 views

### Finding n-th smallest Palindrome number (where 1<=n<=5000 and the palindrome number must have odd number of digits)

I am working on this code from 3 days from a website called Codechef, the code compiles, executes and even give correct results but my code is taking 1.01 sec, but the time limit for question is 1sec,...
• 23
267 views

### Codechef: The Chefora Spell

This is the question currently I am trying to solve of codechef and I am able to get the given test cases result but I am getting Time Limit Exceeded when I am trying to submit. Please let me know ...
• 21
482 views

### Find next smallest number that's representable as a sum of distinct powers of 3

I'm solving this challenge: Given a positive integer number, you have to find the smallest good number greater than or equal to the given number. The positive integer is called good if it can be ...
1 vote
187 views

### Cheapest flights within k stops algorithm in JavaScript

The problem: There are n cities connected by some number of flights. You are given an array flights where flights[i] = [fromi, toi, pricei] indicates that there is ...
92 views

### Finding pair of numbers that minimize a function

This is a problem of a past bioinformatic contest (requires an account). My solution works but is too slow for some test cases. Input format The first line of the input contains one integer $T$, \\$(...
• 5,487
1 vote