# 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.

892 questions
Filter by
Sorted by
Tagged with
237 views

### Largest prime factor function

I have written a function which finds the largest prime factor of some number. This function works but the problem is that it is too slow. For instance, when I enter 600851475143 as a parameter, the ...
616 views

### Dynamic Programming solution for one pile nim game

I have solved the following problem using dynamic programming: Little Deepu and his Girlfriend 1. To paraphrase, We have two players Little Deepu and Kate and M items in the bag B, also we have ...
38 views

### Time complexity of tape equilibirum

As per the instructions on this Tape Equlibrium-Codility I've written the code ...
109 views

### Longest Collatz sequence in Scala

I am trying to find the longest Collatz Sequence: Which starting number, ≤ N, produces the longest chain? If many possible such numbers are there print the maximum one. (1 ≤ N ≤ 5×106) I tried ...
3k views

### Sort characters in a Python string by frequency

I wrote a solution to the leetcode problem Sort characters by frequency and the solution passes 34/35 test cases. On the last test case, there is a "time limit exceeded" error with an input string of ...
228 views

### CodeForces: Creating the Contest

I wrote a solution to this question. The task is to take an input of n increasing positive integers (1 ≤ n ≤ 2∙105), each entry as large as 109, and find the length of the longest subsequence where ...
285 views

### Prime pair set finder (Project Euler problem 60)

I made a code that can find the prime sets: The primes 3, 7, 109, and 673, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For ...
2k views

### Hacker Rank Challenge : Find count of substrings which are special palindrome

I am getting timeout for test cases having very large input. -= Challenge Link =- -= Test case example =- Code is working fine as can be checked on ideone. (Note: Here ...
1k views

### Project Euler Problem 21 in Python: Summing amicable numbers

Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b ...
83 views

### Find the first palindrome larger than the given number

Question Input number of test cases. Input each test case and output its next palindrome number. Link: https://www.spoj.com/problems/PALIN/ Language Used: C++14 (gcc 6.3) My code ...
107 views

### Spoj-Prime Generator

Question- Generate all prime numbers between two given numbers. https://www.spoj.com/problems/PRIME1/ My attempt- I used segmented sieve method. ...
651 views

### Hacker rank - Left rotation - PHP code feedback for Timeout

Here is the problem description: https://www.hackerrank.com/challenges/ctci-array-left-rotation A left rotation operation on an array of size $n$ shifts each of the array's elements 1 unit to the ...
64 views

### Counting dinucletotide fractions & j2 index from a genome fasta file

I wrote this code to count the dinucletide fractions that appear in a genome (this is a sequence of two nucleotides, 'A','G','C','T', together). My code also calculates the j2 index (this is a very ...
1k views

### CodeFights: Frisbees

Description You and your friends are seizing another summer day, passing around the frisbee in the park. You have the most fun when the game is fair, so as much as possible, you would all like to ...
1k views

### Find smallest number of squares that sum to a number

Leetcode problem 279 “Perfect Squares” is: Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) I wrote the following solution: ...
525 views

### Project Euler Problem 1 with Python 3 ideal solution

I have been playing around in hacker rank with Python these days, and now pulling my hair out on this question to solve the Euler's problem in the least time required. If we list all the natural ...
1k views

### Climbing the Leaderboard: HackerranK, Terminated due to timeout

I have implemented my solution and I thought it was pretty efficient and passes most of the cases but seems like it fails some of the test cases when the input size is very large. I basically push ...
102 views

### Get owner of ~5 million files and folders using Powershell and Robocopy

I've written a Powershell script that uses Robocopy to get the full path of all files on a drive and then run it through a foreach loop to get the owner for each file and generate it in a CSV. The ...
3k views

### Counting pairs that have a given difference in Java

You will be given an integer k and a list of integers. Count the number of distinct valid pair of integers (a,b) in the list for which a+k=b. For example, the array [1,1,1,2] has two different ...
2k views

### Minimum swaps algorithm terminated due to timeout

I have been trying to solve this question. Given an unordered array consisting of consecutive integers [1, 2, 3, …, n], find the minimum number of two-element swaps to sort the array. I was able ...
852 views

### Blackjack strategy simulation

I'm very new to python (been coding for about two days) and have created a programme that simulates blackjack games so that I can work out optimal strategy over many iterations. The problem is that ...
72 views

### Forming all multiples of 3 using the given digits

I'm working on this kata from Codewars. The task is: Given a certain number, how many multiples of three could you obtain with its digits? Supose that you have the number 362. The numbers that ...
351 views

### Lattice path from Project Euler with Python solution

I was trying to solve this problem called lattice path from Project Euler: Count the number of unique paths to travel from the top left to the bottom right of a lattice of squares. How many such ...
2k views

### Python function to find the next smaller number with same set of digits

Problem: Write a function that takes a positive integer and returns the next smaller positive integer containing the same digits. My solution: ...
124 views

### Finding intersting path in a graph

There is a question in a contest but it doesn't have any answer. I solve it but I get time limit for most of test case. Is it possible to improve my code or give a better approach? Question There is ...
77 views

### Replacing birth year column values with calculated age value

I have a stored procedure that is taking more than 2 hours to complete and I noticed the below SQL is taking close to 25 mins for updating a million+ values. There are multiple steps like this and ...
341 views

569 views

### C++ code to read, sort, and write data

I had written code in C++ to create transformation filters to get input, sort (custom_sorting and existing sorting routine) and write the output to stdin and file. When I presented it to my teacher, ...
559 views

### Finding the distance between the two closest points in a 2-D plane

Here is my code: ...