Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

5
votes
2answers
878 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
1answer
77 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
510 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
64 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
1answer
92 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 ...
6
votes
2answers
90 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
56 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
93 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
49 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
59 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
438 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
62 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 ...
4
votes
2answers
99 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
76 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
106 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
33 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 ...
1
vote
2answers
124 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
28 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
181 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
274 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
97 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
79 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
54 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
39 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
106 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
37 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
113 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 ...
3
votes
1answer
71 views

Transmission Of Messages

I have an assignment to solve this problem. Problem Description Bob the Cat is building a new system, dubbed the Cats Transmission System (CTS). This horribly inefficient system utilises cats to ...
2
votes
1answer
79 views

Finding maximum homework grade ECOO 2018

I'm trying to solve ECOO 2018 round 2(regionals) question 2 to prepare for the upcoming contest. Basically, in the question George has to achieve the maximum possible grade by completing the right ...
0
votes
0answers
46 views

The number having odd divisors between 2 numbers

I am trying to solve a problem from Hackerearth. I'm able to solve sample testcases but somehow when I am submitting the solution it gives time limit exceeded error or wrong output message. Problem ...
3
votes
1answer
347 views

A binary search solution to 3Sum

I tried a binary solution to 3Sum problem in LeetCode: Given an array nums of \$n\$ integers, are there elements \$a\$, \$b\$, \$c\$ in ...
0
votes
0answers
83 views

Hackerrank All Women's Codesprint 2019: Visually Balanced Sections

Link: https://www.hackerrank.com/contests/hackerrank-all-womens-codesprint-2019/challenges/visually-balanced-sections/problem Problem Description A rack has \$n\$ horizontal compartments. The ...
2
votes
0answers
58 views

lowest common ancestor with square root decompostion

This is my implementation of lowest common ancestor problem,I tried to solve it using square root decomposition pre processing time : O(n) query time:O(sqrt(h)) h -> height of tree This ...
3
votes
1answer
46 views

GreetingCard problem with Coordinates

This is a practice problem on Kattis I have exceeded the time limit for the 5th out of 11 test case. Can anyone inspire me what could be done to optimize the code? Problem Description Quido plans ...
4
votes
2answers
86 views

Code to find the sums of building heights

Remains You've recently stumbled upon the remains of a ruined ancient city. Luckily, you've studied enough ancient architecture to know how the buildings were laid out. The city had \$n\$ ...
3
votes
1answer
209 views

Ranking Score System

I have an assignment to solve this problem. There are a total of 12 test case files, 1 of which that I have failed due to exceeding limit on the script. Question Description Bob has somehow ...
2
votes
1answer
42 views

Calculating the potential of a matrix of size (424600, 55)

I have the following working code to calculate the potential of a matrix after normalizing the matrix. But it is too much time consuming. Is there a way to make this code run faster? ...
2
votes
2answers
75 views

Project Euler, Problem 273: finding perfect-square partitions

Problem: Consider equations of the form: \$a^2 + b^2 = N; 0 \leq a \leq b; a, b, N \in \mathbb{N}\$. For \$N=65\$ there are two solutions: \$a=1, b=8\$ and \$a=4, b=7\$. We call \$S(...
6
votes
1answer
320 views

Block storage rewrites

Summary In a block storage system, new data is written in blocks. We are going to represent the flash memory as one sequential array. We have a list of block writes coming in the form of arrays of ...
0
votes
0answers
41 views

Counting events that occur in some time intervals

I have a python code where I need to count the number of ids in a given range of timestamps as : ...
9
votes
2answers
554 views

List elements digit difference sort

I am doing a code challenge of codesignal.com which ask for following things: Given an array of integers, sort its elements by the difference of their largest and smallest digits. In the case of a tie,...
1
vote
2answers
69 views

Determine whether a node is reachable

I am working on this HackerRank problem but running into time constraint issues. Basically, given two arrays, we need to determine if the ith element of the second array is reachable by the ith ...
2
votes
1answer
89 views

Given a string and a word dict, find all possible sentences

I have been trying to figure out how to meet space and time complexity requirements for the following leet code question. I have come up with two versions, one that meets the time requirements and ...
14
votes
5answers
4k views

Hacker Rank: Array left rotation

This code is to solve the Hacker Rank problem array left rotation. A left rotation operation on an array of size n shifts each of the array's elements 1 unit to the left. For example, if 2 left ...
1
vote
1answer
42 views

HackerRank Left rotation code using Java 8

I tried to solve this Left Rotation problem on HackerRank. My code works out for most test cases, but for some it doesn't, probably because they have large number of data. So there seems to be some ...
3
votes
2answers
56 views

firstDuplicate of array

This question has been asked for other languages, but I haven't seen it for C++. Most notably here and here. Given an array a that contains only numbers in the range from 1 to a.length, find the ...