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
5 votes
1 answer
71 views

Connecting ropes with minimum cost

Question: There are given N ropes of different lengths, we need to connect these ropes into one rope. The cost to connect two ropes is equal to sum of their lengths. The task is to connect the ropes ...
2 votes
1 answer
29 views

Pairwise Max Product

This python program takes user input of the number of elements in a list in the variable b and then takes user input of the list elements in list a. It then finds out the maximum product of a pair of ...
2 votes
1 answer
54 views

Efficient List comprehension with multiple conditions using shift? [closed]

I am new to python. I am trying to get the total number of failures by checking first how did the transition of the column Failure Sensor. Then creating the Start column from devicetimestamp if the ...
1 vote
0 answers
38 views

Web-scraping bountied questions from Stack Exchange sites

I recently built my first web scraper in python, and decided to use SO and SE as test websites. Code ...
  • 123
5 votes
2 answers
919 views

Find the best couple of an array in 1.5 seconds

I faced this exercise. Given a sequence \$S\$ (\$2 <= |S| <= 10^6\$) of numbers (\$1 <= S_x <= 10^7\$), determine \$max(abs(S_i - S_j) + abs(i -j))\$. Here is the solution I found: ...
3 votes
2 answers
113 views

Find pairs of similar (by hamming distance) bit strings

I have a list of binary strings where each binary string max length is 15. I need to find list of integers which is count of similar (should differ by max 1 bit position) binary strings present in the ...
  • 279
4 votes
4 answers
146 views

Find the missing and duplicated numbers from shuffled range

I'm solving "Unknown amount of duplicates. One missing number.": In this kata, we have an unsorted sequence of consecutive numbers from a to b, such that a < b always (remember a, is the ...
3 votes
2 answers
200 views

Euler Project: Sums of Digit Factorials

MY CODE: ...
-1 votes
1 answer
46 views

Sum of differences between products and LCMs

I've been trying to solve this Codewars problem https://www.codewars.com/kata/56e56756404bb1c950000992 In this kata you need to create a function that takes a 2D array/list of non-negative integer ...
5 votes
2 answers
318 views

Leet Code 139 (Word Break) using a trie with recursion

I was attempting to solve LeetCode 139 - Word Break Given a string s and a dictionary of strings wordDict, return ...
6 votes
2 answers
277 views

Codeforces #806 Problem D: Double Strings

I tried solving the following problem by following the suggested approach to solving the problem in the problem tutorial. However, the online judge still says my solution exceeds the time limit. Is ...
  • 61
4 votes
1 answer
65 views

Decibinary for xth number (Python code)

I created the code for the problem description below. It works for \$N\le10^6\$ but after that it gives a time out error. What I don't understand is how to optimize the code using dynamic programming. ...
4 votes
1 answer
71 views

Time limit error in 'The Minion Game' using python in Hacker Rank

This is the question link for the quick reference. Problem : There are two players Kevin and Stuart have to play a game in which they're pleased to create multiple strings and will get +1 score for ...
1 vote
1 answer
83 views

Find a secret word given an array of triplets? (codewars problem)

The rules for the puzzle are: Each triplet has the rules of how the letters are ordered in the secret word (each letter is followed by the next letter inside the triplet array). all the letters of ...
  • 131
1 vote
2 answers
87 views

USACO Training - Section 1.5 - Arithmetic Progressions [closed]

I am working on the USACO problem Arithmetic Progression. Here is their problem statement: An arithmetic progression is a sequence of the form a, a+b, a+2b, ..., a+...
  • 349
3 votes
1 answer
148 views

Longest Palindromic Substring | Python Code Giving TLE

Problem Statement Given a string s , return the longest palindromic substring in s. Constraints ...
2 votes
3 answers
255 views

Subarrays with length

You are given an array A of length N (where N is as large as 2×105). All elements of the array are positive integers less than or equal to N. Determine the count of subarrays (contiguous subsequences) ...
1 vote
1 answer
105 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
1 answer
54 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
5 votes
2 answers
922 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
6 votes
3 answers
737 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... ...
1 vote
2 answers
114 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
1 answer
152 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 ...
  • 41
2 votes
0 answers
25 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 ...
0 votes
0 answers
61 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
3 votes
1 answer
141 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 ...
  • 143
3 votes
1 answer
93 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
4 votes
1 answer
334 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 ...
2 votes
2 answers
634 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 ...
0 votes
0 answers
75 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 ...
2 votes
3 answers
201 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 ...
0 votes
0 answers
40 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 ...
1 vote
1 answer
43 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
1 answer
97 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 ...
1 vote
1 answer
197 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
2 answers
47 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 ...
3 votes
3 answers
571 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 ...
5 votes
3 answers
502 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. ...
2 votes
3 answers
192 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
1 answer
126 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 ...
  • 279
1 vote
1 answer
89 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
0 votes
1 answer
138 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 ...
3 votes
1 answer
814 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
3 votes
2 answers
94 views

Identify bad versions program

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 ...
2 votes
1 answer
82 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
4 votes
3 answers
119 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
0 votes
1 answer
93 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 ...
  • 43
0 votes
1 answer
206 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
2 answers
215 views

Leetcode 377. Combination Sum IV Javascript Memoization attempt

Problem Statement ...
2 votes
0 answers
174 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 ...

1
2 3 4 5
21