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
1 vote
1 answer
76 views

Reviews a daily fantasy slate to check for duplicate lineups

My code below is used as a back testing tool to review a past Daily Fantasy Sports slate. This code works perfectly but when the contest size (total entrants) gets up to the 30,000 range it takes ...
1 vote
0 answers
43 views

USACO Silver "Wormhole Sort" solver

I'm struggling a bit with a USACO silver question using python, http://usaco.org/index.php?page=viewproblem2&cpid=992. The question provides an unsorted list of numbers (cows) and a number of ...
  • 11
4 votes
2 answers
132 views

Wildcard Matching: LeetCode 44

Follow up post Link to question: Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*' where: '?' Matches any single character. '*' Matches ...
  • 92.9k
2 votes
1 answer
111 views

Dijkstra's Algorithm + an additional cost to start at each node

I am trying to solve the 2009 Canadian Computing Competition Senior #4. The question gives you a map (graph) of different cities, and the cost of transporting something between each city. There are ...
0 votes
1 answer
345 views

sum of intervals kata in codewars

instructions for the kata: Write a function called sumIntervals/sum_intervals() that accepts an array of intervals, and returns the sum of all the interval lengths. Overlapping intervals should only ...
  • 47
2 votes
1 answer
148 views

Find numbers whose product equals the sum of the rest of the range

Instructions for the 'is my friend cheating' kata in codewars are: A friend of mine takes the sequence of all numbers from 1 to n (where n > 0). Within that sequence, he chooses two numbers, a and ...
  • 47
0 votes
1 answer
82 views

Effective encoding-decoding chain determination (time optimization)

Could you please help with speeding-up this code? Input: UTF-8 text (encoded 1-3 times from known pool of encodings). Every time was encoded and decoded by random encoding from pool. Original was koi8-...
  • 1
0 votes
1 answer
51 views

Code compares Columns "A" of two workbooks and copies different information to destination workbook with entire selected row. LastRow count slows code

Code explanation: I have a code, which performs two tasks - To open two workbooks, one being extract info and one destination and it compares the column A with Column A of these workbooks and all ...
  • 3
1 vote
3 answers
168 views

Find numbers whose factors, when squared, sum to a perfect square

I need help optimizing my Python code for CodeWars Integers: Recreation One Kata. We are given a range of numbers and we have to return the number and the sum of the divisors squared that is a square ...
  • 47
4 votes
2 answers
555 views

LeetCode Daily Problem: Remove adjacent duplicated elements

I was doing an exercise from LeetCode in which consisted in repeatedly deleting any adjacent pairs of duplicate elements from a string, until there are only unique characters adjacent to each other. ...
6 votes
2 answers
780 views

Find all combinations of length 3 whose sum is divisible by a given number

I came up with a suitable solution to a HackerRank problem that failed because the execution took longer than 10 seconds on lists that were of very large size. The problem: Given a list ...
2 votes
2 answers
85 views

Print the count of input numbers less than each of mutiple values "q"

I was solving a question in a competition I joined that asked for a program that calculates how many numbers are less than \$q\$. I solved the question but didn't get the full mark because the code ...
  • 23
1 vote
2 answers
76 views

Making my DP algorithm faster - longest palindromic substring

The following code is my solution to a LeetCode question - find the longest palindromic substring. My code is 100% correct, it passed once but it took too long, and in most of the reruns I hit a "...
  • 113
6 votes
1 answer
318 views

HackerEarth challenge: Lunch boxes

I was solving the lunch boxes problem on HackerEarth but as I submitted my solution most of the test cases were passed and the rest showed 'Time Limit Exceeded'. I would be very grateful if you could ...
5 votes
1 answer
192 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
58 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
93 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
47 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
971 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
186 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 ...
  • 319
4 votes
4 answers
272 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
237 views

Euler Project: Sums of Digit Factorials

MY CODE: ...
-1 votes
1 answer
56 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
407 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
470 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
111 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
111 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
127 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
181 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+...
  • 460
3 votes
1 answer
210 views

Longest Palindromic Substring | Python Code Giving TLE

Problem Statement Given a string s , return the longest palindromic substring in s. Constraints ...
2 votes
2 answers
413 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
149 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
60 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
1k 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
835 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
187 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
203 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 ...
  • 39
2 votes
0 answers
28 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 ...
3 votes
1 answer
164 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
139 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
529 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
1k 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 ...
2 votes
3 answers
253 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 ...
1 vote
1 answer
65 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
130 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
627 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
59 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
642 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
689 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
266 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: ...
  • 189

1
2 3 4 5
21