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.

learn more… | top users | synonyms

7
votes
3answers
78 views

Leetcode 56: Merge Intervals

Problem statement Given a collection of intervals, merge all overlapping intervals. For example: Given \$[1,3],[2,6],[8,10],[15,18]\$, return \$[1,6],[8,10],[15,18]\$. My ...
4
votes
1answer
51 views

Shortest Path For Google Foobar (Prepare The Bunnies Escape)

I have been working on Google Foobar since a few days ago. I am currently in the third level but is stuck in the second challenge of "Prepare the Bunnies' Escape." I have checked this post but it did ...
3
votes
0answers
55 views

Find smallest subset of integers having a given sum

Write a function that meets the specifications below: ...
3
votes
2answers
80 views

Finding Permutations of Numbers

I'm trying to solve this challenge, which consists of finding the next biggest number formed by the digits of the passed in number. If it is impossible to find a number larger than the passed in ...
0
votes
2answers
228 views

Capital Movement CodeChef challenge [closed]

PROBLEM Suppose there are 'n' cities in a country out of which, one is the capital. All of the cities are connected through 'n-1' roads so that it's possible to travel between any two cities ...
2
votes
0answers
75 views

Hackerearth Simple Function - Follow-up

Problem statement Let us first describe a SimpleFunction: ...
3
votes
2answers
102 views

Find all trains which overtake another train

My task: find all trains, which overtake another train and return their trainId. Implementation-suggestion: ...
2
votes
1answer
170 views

BFS shortest path for Google Foobar challenge “Prepare the Bunnies' Escape”

This is the Google Foobar challenge "Prepare the Bunnies' Escape": You have maps of parts of the space station, each starting at a prison exit and ending at the door to an escape pod. The map is ...
3
votes
1answer
60 views

UVa 11340 Newspaper challenge (sum of letter values in an article)

I am solving the UVA 11340 problem: Problem Description News agency pays money for articles according to some rules. Each character has its own value (some characters may have value equals ...
1
vote
1answer
59 views

MaxCounters solution

I am doing this Codility problem You are given N counters, initially set to 0, and you have two possible operations on them: increase(X) − counter X is increased by 1, max counter − all ...
5
votes
1answer
190 views

HackerEarth - SimpleFunction

Problem statement Let us first describe a SimpleFunction: ...
1
vote
2answers
44 views

SPOJ - Alphacode - Exceeds Time Limit

I'm trying to solve Alphacode on SPOJ. The challenge is to count the ways to split a string of up to 5000 digits into a sequence of numbers, each ranging from 1 to 26. It works fine for small ...
1
vote
0answers
83 views

HackerRank university codesprint array construction

Problem statement Professor GukiZ has hobby — constructing different arrays. His best student, Nenad, gave him the following task that he just can't manage to solve: Construct an \$n\$-...
12
votes
4answers
938 views

Leetcode 15. 3 Sum

Problem statement Given an array S of n integers, are there elements a, ...
6
votes
1answer
92 views

Filter Duplicate Elements in Haskell

I'm working on HackerRank to try to improve my Haskell skills along side with reading Haskell Programming from first principles. I wrote a program that works, but it seems to time out on large input ...
4
votes
1answer
43 views

Code to calculate minimum number of pushes required to put the whole dominoes set down

The question is this one on UVa, and it basically gives us n, the number of dominoes and (a,b) relations such that pushing ...
1
vote
0answers
47 views

Extract climate variables on species range from worldclim and save into CSV

My code is currently taking too long to extract climate variables from the worldclim dataset. I would like to download the climate data from the link and find the maximum temperature over my species ...
4
votes
1answer
124 views

UVA online p957 - “Popes”

This is the "Popes" problem from UVa Online Judge: On the occasion of Pope John Paul II's death, the American weekly magazine Time observed that the largest number of Popes to be selected in a 100-...
4
votes
2answers
66 views

Time limit exceeded on finding out the GCD and LCM of a Python list

I'm doing this HackerRank problem: Consider two sets of positive integers, \$A=\{a_0, a_1, \ldots, a_{n-1}\}\$ and \$B=\{b_0, b_1, \ldots, b_{m-1}\}\$. We say that a positive integer, \$x\$, is ...
5
votes
1answer
179 views

Google FooBar XOR Checksum Challenge

Google FooBar came up a few days ago and I took it as a challenge to learn python quickly while having fun. However, I ran into one challenge today that has left me stumped, I've come up with a ...
1
vote
0answers
106 views

HackerRank - Matrix Rotation

Problem statement Given a matrix (up to 300 × 300), rotate each element R steps anti-clockwise along concentric rectangular paths (R up to 109). The algorithm is rated as hard on HackerRank. On ...
2
votes
0answers
53 views

Counting numbers in an array that are divisible by any 2 numbers

While solving one question I got stuck with a time limit error. The main objective in question is to count numbers in an array \$A\$ that are either divisible by \$P\$, \$Q\$ or both. Input format: ...
3
votes
1answer
74 views

Analyzing pair by pair DNA sequences with for loops in Python

Here is a code I would need to make far faster: it is made to analyse more than 3000 DNA sequences of more than 100 000 characters each. The matter is I have to compare it by pair, so that would be ...
3
votes
2answers
104 views

Inserting and deleting elements in a list

In my code, I use fast method of reading input and a custom model of list. After reading the input into my 'list'. The problem is that, when I test my code, most answers are correct, but for some ...
0
votes
0answers
41 views

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
votes
2answers
67 views

CodeChef Chewing challenge

The ZCO is today and I did 5 problems to prepare for it overnight. One of the problems is the CodeChef Chewing problem. The code takes an integer N that specifies the number of chewing gums, integer ...
2
votes
1answer
58 views

HackerRank Strange Counter

I wrote a solution to HackerRank Strange Counter: The counter counts down in cycles. At t = 1, the counter displays the number 3. At each subsequent second, the number displayed by the counter ...
1
vote
0answers
68 views

Optimizing Python Code in terms of Time - Recursive Function [closed]

I wrote the following code but it takes a lot of time, about 20 seconds. The code has recursion and the recursion depth doesn't exceed 100 in any case. When it is run a sufficient amount of times ...
2
votes
4answers
161 views

Find the smallest divisible number for the given input 'n' such that number is evenly divisible by 1 to n

Given a number n, the task is to complete the function which returns an integer denoting the smallest number evenly divisible by each number from 1 to ...
3
votes
3answers
349 views

C++ implementation of Hackerrank's “Maximum Element in a Stack”

I just attempted the Maximum Element Challenge on Hackerrank. This question has been posted before in swift Swift Hackerrank Maximum Element in a Stack but it has attracted low views/no answers. ...
2
votes
1answer
58 views

Hackerrank Lower Bound-STL

This is still my first week of learning C++, I solved the lower bound STL challenge in Hackerrank Lower bound STL but I'm having time exceeded issue for long input. I'm open to constructive criticism, ...
0
votes
1answer
116 views

Read a CSV file and do natural language processing on the data

I am studying the techniques of data mining and data processing. I'm doing this through data I've collected and stored in a csv file. The problem is that this filed was very large, to the point of ...
5
votes
2answers
703 views

Solution to Chef and Squares challenge, timing out in Java but not in C++

I was solving a problem on codechef (online judge and contest organizer). I was writing my code in Java and was getting TLE at last testcase where as I wrote the same code in C++ and it was accepted. ...
2
votes
2answers
85 views

Adjusting all depth data in a file by some elevation

The code adds up numbers from two different text files. It opens an input file 'DEPTH.dat' and reads the numbers after some headers as follows: ...
4
votes
1answer
94 views

Finding the max cost from the minimum cost incurred on travelling

This problem is from INOI 2014 , where I have find out the maximum cost of traveling through the cities but taking the minimum possible route cost , here is an excerpt from it, Indian National ...
4
votes
1answer
102 views

Hackerrank Sum vs XoR

I'm in the process of improving my coding style and performance hence I decided to delve into bit manipulation on Hackerrank. I thought the question was straight forward but on large input, my ...
-1
votes
2answers
76 views

Calculating the number of extended family members [closed]

The problem here says to find the number of extended family members of the president, N people live in Sequence Land. Instead of a name, each person is identified by a sequence of integers, ...
7
votes
4answers
146 views

Calculate the number of palindrome numbers in the given ranges

I've written a program that calculates all of the palindrome numbers in the given range, but the code is slightly slower than needed. I've tried to improve algorithmic complexity to the best of my ...
1
vote
1answer
62 views

Summing integers in stream using Fenwick tree

In short, the input is an ordered list of numbers, and we have to sum the numbers from index a to b quickly. For example, assume array[] = {1, 2, 3}. Please sum ...
-1
votes
1answer
101 views

Largest prime factor of a given number

I'm solving Problem 3 in Project Euler: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143? Most answers I found made use of array to ...
1
vote
1answer
294 views

Google FooBar Level 3 - Shortest path to 1

I recently found the Google Foobar challenges and am having a problem with level 3. The goal of the task is the find the minimum number of operations needed to transform a group of pellets down into 1,...
5
votes
1answer
766 views

C program circular array rotation

I'm trying to solve a Hackerrank problem where you perform k array[n] rotations, and at the end, ask for ...
4
votes
2answers
97 views

Matching maximal nodes with velocities

I have written a code which works very good for small data-files (see below). The data file 'WSPL.dat' which I want to evaluate has a size of 2.6 GB and the data file 'VELOC.dat' has a size of 4.3 GB....
2
votes
4answers
241 views

Circular array rotation Java

I have a solution to the HackerRank Circular Array Rotation challenge. It passes 7 test cases out of 15. The rest of them are getting timed out. I think it's because of the huge data set that has ...
1
vote
3answers
63 views

Finding the nth machine encountered on the journey

Recently I came across this problem in the IARCS server,here is an little excerpt from it, A well-known bandit who used to haunt the forests around Siruseri was eliminated by the policemen a few ...
1
vote
1answer
79 views

Project Euler #4 - Largest Palindrome Project - Python

I solved the HackerRank version of the Largest palindrome problem (similar to Project Euler 4) in Python: Find the largest palindrome made from the product of two 3-digit numbers which is less than ...
101
votes
17answers
13k views

Disproving Euler proposition by brute force in C

I wrote a little bit of code to brute force disprove the Euler proposition that states: $$a^4 + b^4 + c^4 = d^4$$ has no solution when \$a\$, \$b\$, \$c\$, \$d\$ are positive integers. I'm no ...
0
votes
1answer
49 views

Recovering permutation from its image sequence

Recently while practicing I came across this problem , here is an excerpt from it, A permutation of the numbers 1, ..., N is a rearrangment of these numbers. For example 2 4 5 1 7 6 3 ...
1
vote
1answer
86 views

Check if strings are substrings of another string in Python

My problem starts with a list A (length around n = 100) of big strings (around 10000 characters each). I also have another q = 10000 strings of length 100. I want to check if each string is a ...
3
votes
1answer
32 views

Determining a value given the coordinates for numbers arranged in a triangular fashion

Numbers are being stacked in the following manner: 7 4 8 2 5 9 1 3 6 10 The x-axis is horizontal and the y-axis is vertical. With that in mind, here are a few ...