# time-limit-exceeded's questions - English 1answer

683 time-limit-exceeded questions.

### Project Euler Problem #23 (non-abundant sums) [closed]

Project Euler Problem 23 A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of \\$28\\$ would be \\$1 + 2 ...

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

### 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 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 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 Counting pairs that have a given difference in Java

2 answers, 53 views java algorithm time-limit-exceeded k-sum
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 ...

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

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

2 answers, 106 views python python-3.x time-limit-exceeded
Problem: Write a function that takes a positive integer and returns the next smaller positive integer containing the same digits. My solution: ...

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

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

### 2 Method to return statistics from a collection with O(1) time and space

I have a DelayQueue, and the goal is to collect statistical information from the collection in O(1) time and space from ...

### 3 Inefficient binary search? Hackerrank - Climbing the Leaderboard

1 answers, 62 views time-limit-exceeded go binary-search
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 ...

### 3 SPOJ GENERAL: sorting by swaps of distance k

I have been trying to solve this simple problem on SPOJ for quite some time now, but I keep on getting TLE (Time limit exceeded) for some reason. Since the problem is in Portuguese, a brief ...

### 3 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\\$ \\$...

### 5 AIO programming challenge - Friendlist - Who has the most friends?

I attempted this sample question from the Australia Infomatics Competition. TL;DR - Each line of input contains two numbers, representing a mutual friendship relationship. The output needs to be the ...

### 1 Create list and add 1 to list values from index [I,R].Print the Occurence of a specific number

0 answers, 30 views python python-2.7 time-limit-exceeded
...

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

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

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

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

### -1 minimum number and number of moves to make all elements (have circular order) of an array equal [on hold]

0 answers, 49 views algorithm time-limit-exceeded
Given an array and a number k (each element is as a disc has a number from 0 to k-1 written around its circumference,Consecutive numbers are adjacent to each other, i.e. 1 is between 0 and 2, and ...

### 8 Compute the height of a tower made of buckets

I need to speed up my algorithm. It is about finding the height of a tower. The tower is built from buckets. Each bucket has height and radius (1 <= height,radius <= 1000). Variable ...

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

### 1 Find max in-order difference in array

Given an array A of integers, find the maximum of j - i subjected to the constraint of A[i] <= A[j]. If there is no solution possible, return 0. Example : A : [3 5 4 2] Output : 2 for the pair ...

### 2 Compare two Excel workbooks, and create a new sheet containing the differences

1 answers, 2.794 views vba excel time-limit-exceeded
I have code that scans and compares two Excel workbooks, and then pastes all of the differences between the two into a new sheet. My code is working properly - the only problem is when the Excel ...

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

### 5 Summed absolute difference of two array

4 answers, 501 views c++ array time-limit-exceeded
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 ...

I have solved a spoj question CLASS LEADER. For each test case there are n students and a paper will be given to student m and now the game starts, the student m will pass the paper by o positions ...

### 11 Aggregate prescriptions per drug in a CSV file

3 answers, 736 views python python-3.x time-limit-exceeded csv
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 Macro to clear cells that do not appear in a master list

1 answers, 41 views vba excel time-limit-exceeded
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. ...

### 3 Programming Contest - Snuke Festival

Problem Statement The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three ...

### 12 3-Sum Problem in Python

I attempted the 3-Sum problem on Leetcode, where the problem asks to find all possible triplets of numbers in a given list such that their sum is 0. My code worked, but it exceeded the time limit for ...

### 14 Leetcode 15. 3 Sum

Problem statement Given an array S of n integers, are there elements a, ...

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

### 10 Finding indices of numbers that sum to a target

3 answers, 3.763 views c++ algorithm c++11 time-limit-exceeded k-sum
I've taken this algorithm question, which is to find the indexes of any two numbers in an array that sum to a given number. It is quite a simple problem to solve. But it is the execution time of my ...

1 answers, 130 views c++ time-limit-exceeded
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 ...

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

### Transforming tabular view of data in an Excel sheet into a vertical view

3 answers, 237 views vba excel time-limit-exceeded
I have the following code that works correctly on small data-sets, but times out and crashes on large data sets. The goal of this code is to take a tabular view of data on one sheet and transform it ...

### 3 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 Writing many cells to sheet causes Excel to not respond, replacing vlookups [closed]

3 answers, 121 views vba excel time-limit-exceeded
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 Minimize array and output the remainder with respect to 1 second time limit

1 answers, 44 views python python-2.7 time-limit-exceeded
This is my code: ...

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

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

### -1 MySQL select between MAX-n1 AND MAX-n2

2 answers, 99 views php sql mysql time-limit-exceeded database
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: ...

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

Here is my code: ...

### Optimization of Factorial Function

This is a solution to the CodeHhef problem FCTRL2 where we are supposed to find the factorial of numbers up to 100. I have tried several techniques but I am always exceeding their time limit (1 second)...

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

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