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
4
votes
1answer
182 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 ...
6
votes
2answers
988 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 ...
4
votes
2answers
622 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 ...
-2
votes
1answer
72 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 ...
3
votes
1answer
80 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. ...
2
votes
2answers
416 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 ...
3
votes
1answer
62 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 ...
7
votes
2answers
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 ...
4
votes
3answers
597 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: ...
-2
votes
1answer
246 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 ...
2
votes
3answers
607 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 ...
3
votes
1answer
65 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 ...
3
votes
2answers
1k 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 ...
5
votes
2answers
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 ...
0
votes
2answers
571 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 ...
2
votes
2answers
71 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 ...
0
votes
2answers
188 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 ...
3
votes
2answers
873 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: ...
6
votes
1answer
118 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 ...
2
votes
2answers
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 ...
3
votes
3answers
315 views

Find k-distinct partitions which contain at least two perfect squares

Problem Statement: A k-distinct-partition of a number \$n\$ is a set of \$k\$ distinct positive integers that add up to \$n\$. For example, the 3-distinct partitions of 10 are \$1+2+7\$ \$...
10
votes
3answers
672 views

Master Locksmith

Description Master Locksmith has just finished the work of his life: a combination lock so big and complex that no one will ever open it without knowing the right combination. He's done testing ...
11
votes
9answers
32k views

Find the repeated elements in a list

You are given an array of n+2 elements. All elements of the array are in range 1 to n. All elements occur once except two numbers, which occur twice. Your task is to find the two repeating numbers. ...
7
votes
3answers
335 views

Counting ways to choose vertices that form a right triangle

Croatian Open Competition in Informatics, contest 3, December 8, 2007 4. DEJAVU \$N\$ points are placed in the coordinate plane. Write a program that calculates how many ways we can choose ...
4
votes
1answer
116 views

Counting out game with std::list

I recently tried to solve the Josephus Problem on Sphere Online to help answer this question but am getting TLE for any solution I come up with. The exact parameters of the problem are: This is ...
1
vote
0answers
110 views

Quora upvotes trends Hackerrank challenge

The following code is my solution to an old problem I found today. Input Format Line 1: Two integers, N (1 ≤ N ≤ 106) and window size K (1 ≤ K ≤ N) Line 2: N positive integers of upvote ...
8
votes
1answer
394 views

Google FooBar “Prepare The Bunnies Escape”

I'm currently working through the google FooBar challenge, and I'm on the third level, in which I have to find the distance between the top left and bottom right points on a grid. The grid is filled ...
11
votes
3answers
836 views

Aggregate prescriptions per drug in a CSV file

I have a question that is similar in spirit to this previously asked question. Nonetheless, I can't seem to figure out a suitable solution. Input: I have CSV data that looks like (FICTIONAL ...
-1
votes
1answer
45 views

Macro to clear cells that do not appear in a master list

The macro below clears cells that do not match any cell in comparison to a range (a master list). It works on small file but is too slow to work for files with large ranges. ...
5
votes
4answers
523 views

Summed absolute difference of two array

Question (SAD Queries on CodeChef) The Summed Absolute Difference (SAD) of two arrays. Given arrays (1-indexed) \$P\$ and \$Q\$ of lengths \$p\$ and \$q\$. Given a collection of \$n\$ arrays ...
1
vote
1answer
135 views

Project Euler #211: Divisor Square Sum

I started doing hackerrank problems only recently and here's my attempt to solve this problem. Basically, you're given two integers N and ...
1
vote
4answers
173 views

Find value that occurs in odd number of elements

I am trying to solve the following exercise using Javascript: A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be ...
4
votes
1answer
162 views

Facebook Challenge

PROBLEM The Facebook campus has N different attractions, numbered from 1 to N in decreasing order of popularity. The name of the ith attraction is Ai, a unique, non-empty string consisting of ...
3
votes
1answer
292 views

AGGRCOW on SPOJ – Maximize the minimum distance between aggressive cows

I am getting a TLE on my submission to AGGRCOW - Aggressive cows on SPOJ: Farmer John has built a new long barn, with N (2 <= N <= 100,000) stalls. The stalls are located along a straight ...
-1
votes
3answers
161 views

Writing many cells to sheet causes Excel to not respond, replacing vlookups [closed]

I have found that my code causes my Excel to 'not respond' when it gets to this for loop, For thisRow = 2 To lastWSrow(outWS). I'm guessing this is because I am ...
1
vote
1answer
50 views
4
votes
1answer
240 views

Inefficient binary search? Hackerrank - Climbing the Leaderboard

I'm learning Golang and have been trying to get 100% on the following Hackerrank practice challenge: Climbing the Leaderboard The code passes ~8 of 11 tests. The Hackerrank tests are time-bound and ...
7
votes
3answers
1k views

The Next Palindromic number

I have incremented an integer in the function nextpalin() and converted it into a std::string for finding whether it's a ...
5
votes
1answer
74 views

Binary searching the turning point of a function

The problem You are given a list of \$ n \$ positive integers. Your task is to split the list into \$ k \$ subarrays so that the largest subarray sum is minimized. The input On the first line you ...
6
votes
3answers
550 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, ...
1
vote
1answer
412 views
4
votes
2answers
117 views

Synchronizing Lists

I'm attempting to solve the problem "Synchronizing Lists" on Kattis.com. In a nutshell, the problem involves being given two lists: the lists are then to be sorted smallest-to-largest, ...
4
votes
1answer
122 views

Longest palindromes in a string

Honestly, I'm doing a practice and get blocked. Problem link. The problem is simple, given a string, calculate the number of max length palindromes (Any substring is valid, which means you can take ...
-1
votes
2answers
109 views

MySQL select between MAX-n1 AND MAX-n2

I just made this link please check this out Online Results I need to select data between 2 values from a table by using MAX because each SID has different VID. My code: ...
3
votes
3answers
204 views

Finding numbers with given gcd and lcm [closed]

I am solving a question in which we are given the LCM and HCF and two numbers 'a' and 'b', our task is to find the pairs of numbers between a and b [inclusive] whose HCF is the given HCF and LCM is ...
3
votes
1answer
239 views

Bovine Shuffle using a queue (USACO Dec 2017 Silver)

I am working on the "Bovine Shuffle" problem from the December 2017 USA Computing Olympiad, and have got it to work for every test case beside two. When I run these two cases on my own computer, they ...
5
votes
1answer
88 views

Web page downloader that supports redirects

I wrote a class that downloads the HTML of a page from the internet. This class also manages redirects. This works well but I'm not very satisfied about time management for slower servers. In fact, if ...
4
votes
1answer
2k views

Split a given number so that their sum adds to another given number

Task You are given a string S containing only decimal digits ('0' through '9') and a number N. Your task is to insert an arbitrary number (including zero) of plus signs '+' into S in order to ...
13
votes
2answers
2k views

Removing neighbors in a point cloud

I have written a program to optimize a point cloud in dependency of their distances to each other. The code works very well for smaller number of points. For 1700 points it takes ca. 6 minutes. But I ...