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.
3
votes
2answers
95 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
36 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
53 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
49 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
66 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
145 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
321 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. ...
1
vote
0answers
28 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
78 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
694 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
68 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
71 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
69 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
124 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
58 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
70 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 ...
0
votes
1answer
128 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
716 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
96 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
156 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
61 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
61 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 ...
92
votes
17answers
12k 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
73 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
31 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 ...
4
votes
1answer
86 views
Hackerrank “Bricks Game”
Problem URL
This is the solution I came up with the minimax problem stated above. I did a top-down recursive approach with memoization, and I think this should be \$O(n)\$, since we are filling out a ...
3
votes
1answer
57 views
Gather information about computers from multiple CSV files
I created a script to import several CSV files from various sources and one CSV file with a list of systems in it. the script searches each CSV file to see if the system exist in the file and if it ...
2
votes
5answers
146 views
Summing 3 consecutive integers in a list to see if the sum matches a specified value
I have a program where users can add integers to a list and then I want to check the list to see if any three consecutive integers in the list sum to a specified value. I have been told that it is ...
1
vote
0answers
18 views
Project Euler - #5 smallest multiple [Ruby using a hash table]
Why will this code will work for a smaller multiple like 10 but time out for anything over 13?
Can this code be refactored to work for larger numbers?
(p.s. I have an alternate solution but wanted ...
0
votes
1answer
53 views
Select random IDs from a table, using MySQLi
I've created a "simple" function that receives a MySQLi resource and, using a custom where query, will fetch random IDs from a provided table.
Some caveats on this:...
1
vote
3answers
246 views
Code for calculating best possible combination in an array
The problem here , requires me to find the best possible combination of values in an array which is nearest to 0 and are adjacent to each other , here is an little excerpt from it,
The government ...
1
vote
2answers
118 views
Calculate the total items used, if for every x items used, you get one additional item to use
I am looking for a way to optimize this code so that it runs faster. I am trying to calculate the total items used, if for every x items used, you get one additional item to use.
This is the code I ...
3
votes
2answers
131 views
Code for calculating the books dispatched
Recently I came across this, here is an excerpt from it,
This is another problem about Indraneel's library. His library has one
long shelf. His books are numbered and he identifies the books by
...
12
votes
2answers
3k views
Project Euler #10 in C++ (sum of all primes below two million)
Project Euler Problem 10 asks for the sum of all the primes below two million.
I'm creating a list of primes and keep checking any new number for divisibility with only prime numbers. I thought it ...
0
votes
0answers
35 views
Getting TLE for SPOJ Bitplay challenge program
I have tried a naive way to solve this problem:
Given a even number N (N ≤ 109) and an integer K, you have to find the greatest odd number M less than N such that the sum of digits in binary ...
1
vote
2answers
49 views
Find numbers with same number of divisors
I tried to resolve this task:
The integers 14 and 15, are contiguous (1 the difference between them,
noticeable) and have the same number of divisors.
...
7
votes
3answers
125 views
3n + 1 programming challenge in Python
I am trying to find a efficient solution for the 3n + 1 problem on uvaonlinejudge. The code I have uses memoization using a dictionary. I am getting a 'Time limit Exceeded' error when I submit the ...
5
votes
3answers
121 views
Matching values from html table for updating values in pandas dataframe
This is more of an exercise for me to get use to Pandas and its dataframes. For those who didn't hear of it:
Pandas is a Python package providing fast, flexible, and expressive
data structures ...
3
votes
1answer
53 views
Find the number of substrings of a numerical string greater than a given num string
Question:
http://qa.geeksforgeeks.org/9744/vinay-queried-interesting-problem-optimization
Input
The first line contains N denoting the length of Target String. This
line is followed by the ...
3
votes
1answer
80 views
Code for dividing gifts equally
I recently came across this problem:
It is Lavanya's birthday and several families have been invited for
the birthday party. As is customary, all of them have brought gifts
for Lavanya as well ...
6
votes
4answers
1k views
Code for calculating citizens beheaded
Recently I came across this problem ,
A despotic king decided that his kingdom needed to be rid of
corruption and disparity. He called his prime minister and ordered
that all corrupt citizens ...
3
votes
2answers
89 views
Count numbers whose digits are only increasing or decreasing
The goal is described here: basically, it is to compute the number of numbers below \$10^n\$ such that its digits are either increasing or decreasing (like 112 or 211, but not like 121).
The original ...
4
votes
2answers
119 views
Number of possible palindrome sequences
Here is the problem description from hackerearth.com:
Rohan loves Palindromes. Palindrome is a string that read same forward
and backward. For example abba is ...
2
votes
2answers
65 views
Optimize Performance challenge 'Vinay Queried '
Input:
The first line contains N denoting the length of Target String. This
line is followed by the Target String. The Target String is followed
by an integer Q denoting the number of queries ...
3
votes
2answers
101 views
Rhezo and divisibility by 7 challenge
There is a big number with N digits and Q questions.
In each question, find if the number formed by the string between
indices Li and Ri is divisible by 7 or not.
Input: First line ...
4
votes
1answer
229 views
BFS shortest path
I have the following code to return the shortest path on a matrix from top left corner to bottom right corner, with the option of removing one of wall cells (marked ...
2
votes
2answers
470 views
Codefights subsequence
I am solving https://codefights.com/challenge/Qjts7cukDvYpDW4Bc/main
My approach is simple.
Get all subsequences by combination.
Simple loop over combinations.
Find minimum.
...
2
votes
3answers
47 views
Ruby function to find numbers whose sum of squares of divisors is a perfect square
I am doing a problem my buddy gave to me and I have my solution which works but needs to be optimised. I have tried to optimise it as much as I can with my knowledge but it seems there is still room ...