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
0 votes
1 answer
60 views

HackerRank Algorithm Problem: Climbing the Leaderboard (Python)

Here is the Hackerrank problem which is related to dense ranking and below is my solution which didn't pass the time limit cases. Any better way to optimize this? ...
peternish's user avatar
3 votes
2 answers
255 views

Trailing Digits

https://www.acmicpc.net/problem/23204 I've solved a programming challenge where you need to count the occurrences of a specific digit at the end of the product of multiples of a given number within a ...
qleoz12's user avatar
  • 141
-1 votes
1 answer
102 views

HackerRank Project Euler 12 (Python) | Highly Divisible Triangular Numbers

I again share my Python code which didn't pass time limit test cases in the HackerRank contest of ProjectEuler. ...
peternish's user avatar
2 votes
1 answer
106 views

calculate the number of ways to pick two different indices

I'm working on a codesignal practice problem You are given an array of integers a and an integer k. Your task is to calculate the number of ways to pick two different indices i < j, such that a[i] ...
Josh's user avatar
  • 21
2 votes
1 answer
89 views

Codeforces: Dasha & Nightmares

so I got started with competitive programming about a day ago and I got stuck on the first random question I tried on codeforces. It's called Dasha and Nightmares. Problem Description: The problem ...
st0n3r's user avatar
  • 73
2 votes
1 answer
246 views

Traveling Salesman Problem for visiting cities

Implement TSP problem using best first algorithm (so it will be backtracking, branch-and-bound, and best-first). Since you are looking for a cycle, the start/finish city is not important. Therefore we ...
Ruiru's user avatar
  • 21
6 votes
1 answer
115 views

One or more planets to line up with the earth a certain amount of times

I have attempted the below question, however my solution is too slow (i.e. It does not fit the 2 second time constrain for java). How can the solution be optimised? While at IOI 2020 in Singapore, ...
Zareef Akoodie's user avatar
1 vote
1 answer
51 views

Find all combinations of two companies grouped by the projects they are tendering for

I am working on the task to get all possible combinations (pairs) of ID's (companies) which participated in one bid and create a new data frame with ID_1, ID_2, matching parameter (tender ID). I have ...
Vasya_Ch's user avatar
2 votes
1 answer
133 views

Find character at given index in a sorted sub strings [closed]

For a given string say dbac the possible substrings are [d,db,dba,dbac,b,ba,bac,a,ac,c]. Sort them and concatenate to a string: ...
technotigr's user avatar
4 votes
2 answers
108 views

Find largest sum not involving consecutive values

There is a question to basically find the largest sum in an array, such that no two elements are chosen adjacent to each other. The concept is to recursively calculate the sum, while considering and ...
BlazeRod11's user avatar
1 vote
1 answer
101 views

Positive Segments

I'm trying to solve the following question: You have an array A of size n, containing −1 or 1 only, and s segments (not necessarily different). Each segment is defined by 2 integers li and ri (1 ≤ li ...
driver's user avatar
  • 212
-2 votes
1 answer
54 views

Market Portfolio Binary Search Tree [closed]

I'm trying to solve the following problem here: First line of input contains the number of days D. The next d lines contains a character c and a number x. If c is B, then buy stock . If c is S, then ...
driver's user avatar
  • 212
4 votes
2 answers
535 views

O(nlogn) Lexicographically minimal rotation code but tle on this particular case

Based on a small suggestion here , this code tries to find lexicographically minimal rotation (question) by successively comparing two adjacent substrings in the very left , that can potentially give ...
Aryaman 's user avatar
2 votes
1 answer
173 views

k-dice Ways to get a target value

I'm trying to solve the following problem: You have a k-dice. A k-dice is a dice which have k-faces and each face have value written from 1 to k. Eg. A 6-dice is the normal dice we use while playing ...
driver's user avatar
  • 212
3 votes
1 answer
988 views

Knock down tall buildings

I'm trying to solve the following problem: As you know Bob likes to destroy the buildings. There are N buildings in a city, ith building has ai floors. Bob can do the following operation. Choose a ...
driver's user avatar
  • 212
9 votes
3 answers
2k views

Repeatedly remove a substring quickly

I'm trying to solve the USACO problem Censoring (Bronze), which was the first problem for the 2015 February contest. My solution works for some test cases, but then times out for test cases 7-15. I ...
Kimi M's user avatar
  • 101
2 votes
1 answer
98 views

USACO Arithmetic Progression

The problem statement: An arithmetic progression is a sequence of the form a, a+b, a+2b, ..., a+nb where n=0, 1, 2, 3, ... . For this problem, a is a non-negative integer and b is a positive integer. ...
Michael Granger's user avatar
-2 votes
2 answers
120 views

Lower-Bound algorithm getting Time Limit Exceeded

...
Shakhawat Hossain SHIHAB's user avatar
0 votes
2 answers
107 views

Web scraping spider

I'm currently working on my first web scraping project and I need to scrape a lot of websites. With my current code it takes more than a day but for my project I need to scan the same websites every 5 ...
Max's user avatar
  • 17
-1 votes
1 answer
143 views

HackerRank "Digit sum" challenge

Here's the question: ...
The Infinite Star's user avatar
2 votes
2 answers
93 views

For two sequences N and M, display counts of elements n from N below each m from M up to the first n above m

A school's task: There are two sequences n_tab and m_tab. For every element m in m_tab ...
Szyszka947's user avatar
3 votes
0 answers
36 views

Cross-classification of imagery from several regions in GEE

For a project I want to do the following: Use imagery from 17 different regions in Europe to train 17 RF classifiers Use those 17 classifiers to classify each of the regions It will be a multi-...
pottsbill's user avatar
1 vote
1 answer
106 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 ...
safo2238's user avatar
1 vote
0 answers
86 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 ...
Luke's user avatar
  • 11
4 votes
2 answers
238 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 ...
Martin York's user avatar
  • 94.3k
2 votes
1 answer
141 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 ...
Justin Cheng's user avatar
0 votes
1 answer
1k 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 ...
mlk's user avatar
  • 47
2 votes
1 answer
172 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 ...
mlk's user avatar
  • 47
0 votes
1 answer
102 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-...
Kir S's user avatar
  • 1
0 votes
1 answer
58 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 ...
Rokas's user avatar
  • 3
1 vote
3 answers
203 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 ...
mlk's user avatar
  • 47
4 votes
2 answers
638 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. ...
Rafael Carro Gaudim's user avatar
6 votes
2 answers
1k 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 ...
Nicholas Hansen-Feruch's user avatar
2 votes
2 answers
87 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 ...
A15's user avatar
  • 23
1 vote
2 answers
100 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 "...
ela16's user avatar
  • 113
6 votes
1 answer
507 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 ...
Devansh Kumar's user avatar
5 votes
1 answer
322 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 ...
Sherlock-Holmes-2-2-1's user avatar
2 votes
1 answer
167 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 ...
Pratik Roy's user avatar
2 votes
1 answer
126 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 ...
Noobie1997's user avatar
1 vote
0 answers
53 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 ...
DialFrost's user avatar
  • 123
5 votes
2 answers
976 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: ...
Nicolò Teseo's user avatar
3 votes
2 answers
259 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 ...
Harry's user avatar
  • 379
4 votes
4 answers
393 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 ...
post_lupy's user avatar
3 votes
2 answers
317 views

Euler Project: Sums of Digit Factorials

MY CODE: ...
CaptainPotato's user avatar
-1 votes
1 answer
67 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 ...
post_lupy's user avatar
5 votes
2 answers
478 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 ...
Shawn Frank's user avatar
6 votes
2 answers
673 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 ...
Sam's user avatar
  • 61
4 votes
1 answer
208 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. ...
vijayalakshmi_bhagat's user avatar
4 votes
1 answer
136 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 ...
Sanjay Varyani's user avatar
1 vote
1 answer
190 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 ...
Jonas's user avatar
  • 131

1
2 3 4 5
21