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
2
votes
1answer
62 views

How can I make my solution to “Climbing the Leaderboard” not time out?

I tried to solve the following challenge and optimize the solution but my code still times out. My code is below. Problem statement Climbing the Leaderbord Alice is playing an arcade game and ...
19
votes
3answers
3k views

Loading military units into ships optimally, using backtracking

I solved the following problem using backtracking: We are given a list of military units, their weight and their (numerical) strength. We have a number of ships with a limited carrying capacity....
2
votes
1answer
35 views

Daily SQL job to delete records older than 24 hours

Below is a delete job to delete 1M+ records daily and takes 13 hours to complete and sometimes more than that. I need to optimize this. The table tblcalldatastore is being inserted 24*7 through a ...
3
votes
1answer
65 views

CodeChef's Tree MEX (Minimum Excludant) challenge

This code is a solution for CodeChef's Tree MEX problem: Minimum excludant (or MEX for short) of a collection of integers is the smallest non-negative integer not present in the set. You ...
4
votes
1answer
27 views

Search for strings in a list that have > 90% similarity

Explanation: I am working on String comparison in which I want to cross-compare the list of the same input string. For the same string, I am continuing the loop but if a single string will have ...
0
votes
2answers
48 views

Read coordinates from many files and calculate polygon areas

My goal with this snippet is to create an array of coordinates which in turn is a tuple of 68 elements, area and modified area array for all 10k elements and assign it to the ...
0
votes
0answers
503 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
1answer
60 views

Optimal BST challenge

I was coding the problem here. I think I have solved it, but I ran into time limit exceeded issues. I am new in Competitive Programming, so I was looking for a better, time efficient logic for solving ...
6
votes
4answers
526 views

Counting multiples of 3 up to a given number

I'm attempting a practice problem in Codeforces that requires you to find the number of multiples of 3 less than or equal to a given number. I have written the following code but it gives a TLE once ...
1
vote
2answers
76 views

Generate a large block diagonal covariance matrix with exponential decay

I am implementing Kalman filtering in R. Part of the problem involves generating a really huge error covariance block-diagonal matrix (dim: 18000 rows x 18000 columns = 324,000,000 entries). We denote ...
2
votes
1answer
47 views

Coding Challenge: Kattis

Short problem description: A sequence of numbers are antiarithemtic if there exists no three numbers a_i, a_j, ...
2
votes
1answer
39 views

Finding the number of times the code will generate an alert depending upon whether the transaction is fraudulent

Please refer to this problem from Hackerrank HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a ...
4
votes
1answer
77 views

Optimising iteration and substitution over large dataset

I have the following code: ...
3
votes
2answers
122 views

Jump Game - Leetcode

Below is my solution for the LeetCode Jump Game Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents ...
1
vote
0answers
48 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 ...
4
votes
2answers
61 views

Finding a vertex of a tree such that every subtree rooted at that vertex is of a uniform color

I'm trying to optimally solve codeforces problem 763A: Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so ...
5
votes
1answer
69 views

Finding sum of divisors of numbers between the range (1 to 1e16)

The exact link to the question : https://www.spoj.com/problems/DIVSUM2/ Input: An integer stating the number of test cases (equal to 500), and that many lines follow, each containing one integer ...
4
votes
1answer
87 views

Agent based model in Python

My model is based on the Ultimatum Game. I won't go into the intuition behind it but generally speaking it functions as follows: The game consists of a n × n lattice on which an agent is placed at ...
5
votes
2answers
183 views

Bit-based universe simulation

I am working with this problem (https://open.kattis.com/problems/whowantstoliveforever). As the problem states, my program has to determine if the universe lives or dies based on the input 0s and 1s. ...
5
votes
2answers
973 views

Fastest path on a snakes and ladders board

I am not looking for a detailed review of this code as I am aware it is very inefficient. The main reason for posting this is to see if there is a better way to achieve my goal (I am certain there ...
7
votes
1answer
1k views

Python program to find a word ladder transforming “four” to “five”

I saw this Puzzling problem and thought I would try to write a Python program to solve it. The task is to transform "four" to "five", forming a new four-letter word at each step, replacing one letter ...
6
votes
2answers
100 views

Program for activity selection exceeds time limit

I've been trying to solve this problem for some while and the solution I have come up with exceeds the lime limit by 1-3 ms and 2 out of 10 tests get a memory issue error. Why is that? This is the ...
7
votes
3answers
511 views

Finding dictionary keys whose values are duplicates

I currently have a dictionary (Duplicate_combos) that has a unique identifying number for the key value and the value is a list with two elements, a company code ...
7
votes
1answer
101 views

Google “Wiggle walk”

I am doing Kickstart's problem Wiggle Walk. I have tried to code with matrix, dictionary and nested dictionary but the time exceeds the limit in each submition. Can anyone help me optimize it better ...
3
votes
2answers
226 views

Solution to Kickstart's Wiggle Walk

I'm trying to optimize my solution to Wiggle Walk for Kickstart's round 1C. Problem Banny has just bought a new programmable robot. Eager to test his coding skills, he has placed the robot ...
17
votes
2answers
2k views

Yandex programming contest: Alarms

I've tried to solve this challenge about 4 hours during the contest, but all my attempts exceeded the time limit. I tried to solve it with min-heap, but can't pass all the tests. How it can be solved ...
7
votes
2answers
105 views

Finding collisions of the first few bits of a SHA-1 hash

My objective is to find a hash collision of my modified hash function. Assuming my modified hash only outputs the first 36 bits of SHA-1. As we know, SHA-1 is a 160-bit hash value, hence, we only need ...
2
votes
0answers
68 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 ...
3
votes
3answers
110 views

Calculate the nth Fibonacci number, mod m

I was trying to output F(n) mod m to find the remainder of Fibonacci number, where F(n) could be a very big number: ...
2
votes
1answer
58 views

HackerRank New Year Chaos: arriving at a given list using neighbor swaps

I am trying to solve the HackerRank New Year Chaos problem where the aim is as follows: A vector of size n is having values ...
3
votes
1answer
86 views

Project Euler #357: Prime generating integers

Project Euler Problem 357 asks: Consider the divisors of 30: 1,2,3,5,6,10,15,30. It can be seen that for every divisor d of 30, $$d+30/d$$ is prime. Find the sum of all positive integers n ...
0
votes
1answer
453 views

CodeChef Matches challenge

I am solving some problems from CodeChef but I am stuck on the Matches problem: Ari and Rich are playing a pretty confusing game. Here are the rules of the game: The game is played with ...
5
votes
2answers
75 views

Birthday paradox simulation

I'm writing a simulator which checks how many balls we need to occupy every box or how many balls we need for any box has at least 2 balls (birthday paradox). I wrote the script in python and it is so ...
5
votes
2answers
160 views

Hackerrank.com - Sherlock and Anagrams

Summary: Given a string find the number of anagramic pairs of substrings of it. e.g 'abba' pairs are [a,a],[b,b],[ab,ba],[abb,bba] so we have 4 pairs. I'm wondering if anyone can help me improve my ...
3
votes
1answer
83 views

Calculating pi via collisions

This code calculates pi via collisions; it asks for a user input of N which determines the mass of the second block. It is fully working, it just takes forever to run when N >= 2. I want to be able ...
7
votes
1answer
122 views

Hackerrank: Computer Game (max-flow problem with integer factorization)

I am working on a coding challenge from the Hackerrank site. Given two equal-length arrays of integers, with values from 2 to 109, find the maximum number of times we can remove a pair (Ai, Bj) where ...
9
votes
4answers
2k views

A faster way to compute the largest prime factor

I am self-learning js and came across this problem(#3) from the Euler Project The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? ...
1
vote
0answers
41 views

TLE error: Remove element from LinkedList [closed]

I am working on an easy LinkedList basic operation problem on Remove Linked List Elements - LeetCode Remove Linked List Elements Remove all elements from a linked list of integers that ...
2
votes
2answers
378 views

New Year Chaos JavaScript, needs to be sped up

Similar to this question but this is for Python Original problem with description on hacker rank I am currently trying to iterate through a large number of arrays and count how many times numbers ...
0
votes
1answer
31 views

Time limit exceeded in K-th symbol in Grammar (LeetCode)

I am taking efforts to solve problem K-th Symbol in Grammar - LeetCode K-th Symbol in Grammar On the first row, we write a 0. Now in every subsequent ...
5
votes
1answer
209 views

Finding the upper and lower bound using binary search

I am trying to solve this InterviewBit question https://www.interviewbit.com/problems/search-for-a-range/. My code for this seems to be working properly and it does give me the correct answers on my ...
0
votes
1answer
291 views

Solution to Codejam 2019's Pylons

I'm trying to solve Pylons from the 2019's round 1A. Problem Our Battlestarcraft Algorithmica ship is being chased through space by persistent robots called Pylons! We have just teleported ...
1
vote
1answer
66 views

Merging records from one spreadsheet into another

I have created the code below that compare two spreadsheets . It initially compares the range of value from sheet1 ("Status") to sheet2 ("Interface") . Whenever a range matches with the ranges present ...
3
votes
1answer
198 views

Google Kick Start Practice Round 2019 - Mural

My code exceeds the time limit on the second test set. A suggestion/hint of a better algorithm would be appreciated. Problem Thanh wants to paint a wonderful mural on a wall that is N ...
1
vote
1answer
80 views

Sum of number's quotients when divided by exact powers of 2

Problem I have written code to solve this challenge: Given a formula: GCD(x,y) means the GCD (Greatest Common Divisor) of x and y. For example: if N=2, then: f(2) = 1/GCD(1,...
1
vote
1answer
63 views

Programming Challenge from Kattis: Distinctive Characters

I'm currently working on this problem from Kattis. In short, we're supposed to find the string that has the least similarity to any other string given. Every element of a string is either 0 or 1. ...
1
vote
1answer
50 views

Exceeded time limit to solve super pow

I tried to solve the Super Pow - LeetCode Super Pow Medium Your task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in ...
2
votes
3answers
111 views

Looking for all numbers where each digit is bigger than the previous digit

This is the "Increasing Number problem", where we are looking for all numbers with \$n\$ digits where each digit is bigger than the digit before it. Or in Mathematical therms where: $$\mathit{...
2
votes
1answer
39 views

Kattis Problem 'Mali'

I wrote a solution to the Mali problem on Kattis: Given inputs a1, a2, a3, …, an and b1, b2, b3, …, bn, determine n pairings (ai, bj) such that each number in the A sequence is used in exactly one ...
4
votes
2answers
114 views

Heights of Cats

I have an assignment to solve this problem. However, I have exceeded the time limit required, can anyone suggest where to improve my code? Cats like to sit in high places. It is not uncommon to see ...