All Questions
Tagged with programming-challenge performance
629 questions
5
votes
4
answers
1k
views
Optimizing Bingo Caller Method
I am dong a competitive programming problem I have passed all the tests.
but my program times out. I need help optimizing my code so it can run faster.
Task:
Finish method: ...
5
votes
3
answers
1k
views
Adding Reversed Numbers - ADDREV on SPOJ
Today I tried solving this problem on SPOJ, in which you reverse the digits of two numbers, add them, and print the reversed digits of the sum. (When reversing, leading zeroes in the result should be ...
5
votes
3
answers
360
views
Go Aaaaaaaaaaah
The problem is described in full here - Aaah!.
Input
The input consists of two lines. The first line is the “aaah”
Jon Marius is able to say that day. The second line is the “aah” the
doctor wants to ...
5
votes
3
answers
867
views
Project Euler 127 - abc-hits
Problem (Rephrased from here):
The radical of \$n\$, \$rad(n)\$, is the product of distinct prime factors of \$n\$. For example, \$504 = 2^3 × 3^2 × 7\$, so \$rad(504) = 2 × 3 × 7 = 42\$.
We shall ...
5
votes
3
answers
1k
views
Project Euler # 15 Lattice paths in Python
Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down,
there are exactly 6 routes to the bottom right corner.
How many such routes are there through a 20×20 ...
5
votes
3
answers
2k
views
Finding numbers whose product of the digits are perfect squares
How can I decrease the running time and compile time of the following code?
Given three integers A, B and ...
5
votes
3
answers
729
views
Tweets per second
This challenge is from Talent Buddy:
Tweets per second
Japan Castle in the Sky airing broke a Twitter
record on August 3, 2013. At one point during the classic anime movie
showing, people ...
5
votes
4
answers
530
views
LeetCode: Roman to Integer in Java
I tried solve this easy leetcode challenge in java. Challenge link
Here is my solution
...
5
votes
2
answers
2k
views
MaxCounters solution in C# from Codility
I programmed a little in java a while back, and now I'm learning C#.This is the first exercise of "medium" or "respectable" difficulty according to Codility, so I'm pretty pleased of finding out that ...
5
votes
3
answers
10k
views
Find the corresponding closing parenthesis
Problem:
"Sometimes (when I nest them (my parentheticals) too much (like this
(and this))) they get confusing."
Write a function that, given a sentence like the one above, along with the ...
5
votes
2
answers
137
views
Counting matrices
I need help optimizing my code to run faster (it works but I get Time Limit Exceeded) for this problem.
(Don't pay attention to readInt() function, its only used ...
5
votes
2
answers
943
views
Count Scorecards challenge problem related to partition number theory
I am having a challenge problem. I have solved the problem but my solution is slow.
The problem is basically the distribution of scores among players. e.g for a 2 player game the possible scorecards ...
5
votes
2
answers
1k
views
(Leetcode) Minesweeper game
This is a Leetcode problem -
Let's play the Minesweeper game
(Wikipedia,
online game)!
You are given a 2D char matrix representing the game board. 'M'
represents an unrevealed mine, 'E' ...
5
votes
1
answer
1k
views
Google Kick Start Practice Round 2019 - Mural
My code exceeds the time limit on the second test set. A suggestion/hint of a better algorithm would be appreciated.
Problem
Thanh wants to paint a wonderful mural on a wall that is N ...
5
votes
1
answer
924
views
Count pairs in list of integers such that their addition is equal to the input value
Given a List<int>, the problem I am trying to solve is:
Find the number of unique pairs in List<int> such that their ...
5
votes
5
answers
3k
views
Number of sub strings with same first and last character
Problem Statement:
You are given a function \$f(x)\$, where \$f(x)\$ is \$1\$ if the first and last characters of string \$x\$ are equal; else it is \$0\$.
You are given a string \$S\$ and you ...
5
votes
3
answers
4k
views
"Utopian Tree" challenge optimization
Problem statement
The Utopian tree goes through 2 cycles of growth every year. The first growth cycle occurs during the monsoon, when it doubles in height. The second growth cycle occurs during the ...
5
votes
5
answers
2k
views
Project Euler #3 in C# - largest prime factor
I just started doing the Project Euler challenges and right now I'm on Challenge #3 - The largest prime factor of 600851475143.
I wrote some code and tried to optimize it based on some other Stack ...
5
votes
2
answers
1k
views
HackerEarth Girlfriend's Demand challenge, solved two ways
I solved the Girlfriend's Demand challenge on HackerEarth. In summary:
Input: First line of the input contains a string S. Next line contains an integer Q, the number of queries. Each of the next ...
5
votes
2
answers
3k
views
Reverse Game HackerRank Ruby Solution
Problem Statement
Akash and Akhil are playing a game. They have N balls numbered from 0
to N−1. Akhil asks Akash to reverse the position of the balls,
i.e., to change the order from ...
5
votes
3
answers
904
views
Project Euler 38: Pandigital Multiples
I just solved Project Euler 38 and was wondering if you guys could provide some suggestions on how to speed it up. I've tried adding extra conditions but they increase the time. Any ideas on how to ...
5
votes
1
answer
350
views
Leetcode: Largest Number
I was trying out leetcode's Largest Number.
As per the challenge's description:
Given a list of non-negative integers nums, arrange them such that
they form the largest number and return it. Since ...
5
votes
3
answers
1k
views
Printing pyramids in C (CS50)
I'm taking the CS50 course, and we're asked to create a program which takes an input (the total height of the pyramid) and outputs a pyramid of that height.
i.e Here’s how the program might work if ...
5
votes
2
answers
509
views
Frequency Queries (Hackerrank)
This is the problem:
You are given queries. Each query is of the form two integers described below:
1 x: Insert x in your data structure.
2 y: Delete one occurrence of y from your data ...
5
votes
2
answers
1k
views
Time conversion program optimization
I have just finished working on a problem on hackerrank dealing with time conversion in C++.
I'm still fairly new to programming as I only have a few semesters of programming classes under my belt ...
5
votes
2
answers
295
views
Solution to the 0-1 knapsack
I'm using a one-dimensional array with length \$W(\text{weight capacity})\$. Is this is any better than the solutions with a two-dimensional array \$W, n\$ where \$n\$ is the number of items? I'm ...
5
votes
1
answer
82
views
Finding all factors and prime factors of a number
I am working on the Project Euler, number 3 project (finding the largest prime factor of 600851475143), but I wanted to take it a step further and write something that will list all factors and prime ...
5
votes
2
answers
531
views
Pascal's Triangle Java (performance)
I need to get some information about the Pascal Triangle.
What is a pascal triangle ?
It is a triangle of integers with 1 at the top and at the sides. Any number inside is equal to the sum of the ...
5
votes
1
answer
2k
views
Project Euler 76: Counting summations
Project Euler Problem 76 asks:
How many different ways can one hundred be written as a sum of at least two positive integers?
My code is correct but just works slowly.
...
5
votes
1
answer
5k
views
Code Vita: Chakravyuha
Problem Statement
A Chakravyuha is a wheel-like formation. Pictorially it is depicted as
below
A Chakravyuha has a very well-defined co-ordinate system. Each point
on the co-...
5
votes
2
answers
1k
views
Segmented Sieve of Eratosthenes
I implemented this for the Prime Generator problem on SPOJ, but I am only getting 0.01s run-time, and would like to be able to match the run-times of the top submissions, which are all 0.00s.
What are ...
5
votes
2
answers
673
views
Project Euler #23 Non-abundant sums
I'm having trouble optimizing the Project Euler problem number 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 ...
5
votes
2
answers
5k
views
Optimizing O(m n) solution for longest common subsequence challenge
Given two strings string X of length x1 and string Y of length ...
5
votes
1
answer
346
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 ...
5
votes
2
answers
911
views
Matrix of articles and authors from large JSON dataset
Given the following JSON data containing 4 articles by 4 different authors:
...
5
votes
1
answer
1k
views
Speed up lights-out variant solver in pure Python
I'm doing some challenges to learn new and interesting concepts, this one is about a Lights out variant, instead of toggling only the adjacent tiles, it toggles the whole row and col.
It must be ...
5
votes
1
answer
2k
views
Optimizing Code for Project Euler Problem 14
For Project Euler problem 14 I wrote code that runs for longer than a minute to give the answer. After I studied about memoization, I wrote this code which runs for nearly 10 seconds on Cpython and ...
5
votes
2
answers
218
views
Creating a list from combinations of the original data
I am trying to create a list based on some data, but the code I am using is very slow when I run it on large data. So I suspect I am not using all of the Python power for this task. Is there a more ...
5
votes
1
answer
95
views
Linear regression on points specified by the user in a GUI
Here's my take on the Linear Regression exercise from John Zelle's Python book.
Open a window, let the user click on as many points as they want. Upon pressing the "Done" button the regression line ...
5
votes
2
answers
163
views
Counting the occurrences of bank account numbers for SPOJ challenge
I am solving a problem on SPOJ and am currently unsatisfied with my submission time, given that my fastest time is 0.28s (which ranks me 123/5037) and the leading submission is 0.04s.
The problem is ...
5
votes
3
answers
3k
views
HackerRank woman codesprint: minimum cost
Lauren has a chart of projected prices for a house over the next n
years, where the price of the house in the i-th year is <...
5
votes
2
answers
197
views
Euler Project 14 (Longest Collatz Sequence)
Project Euler 14 asks: Which starting number, under one million, produces the longest Collatz sequence?
I've been trying to optimize this solution to execute in less then 1s. Agenda for first 50 ...
5
votes
2
answers
6k
views
Mars Rover Simulator
Problem Statement
Consider a rover and a plateau of size nxn. The rover takes three type of instructions L,R and M. 'L' and 'R' rotate the rover in the left and right direction. 'M' moves the ...
5
votes
1
answer
138
views
Equivalent passwords ACPC 2014
I am preparing for ACM-TCPC (Tunisia). So I started solving problems from past ACM-ACPC versions. But I got stuck in the Problem I from 2014.
The problem consists of finding the number of non-...
5
votes
1
answer
212
views
How to lose plants and aggravate people
Courtesy of a few posts around here I've discovered HackerRank. Poisonous Plants is one of their challenges.
Of course, skip the following if you'd like to try it yourself.
Challenge:
There are \$...
5
votes
3
answers
3k
views
Calculating the ranks of classmates' exam grades
The questions from hackerearth:
Geeko is in worry now because an exam is coming up and he has to know
what rank he can get on exams. So he goes back into the the school records
and finds the ...
5
votes
2
answers
13k
views
HackerRank Algorithm Challenge 1: Insertion sort
This is my solution for HackerRank's first "Algorithm Challenge, Insertion Sort Part 1". The challenge is to sort the array from least to greatest, the input being an array in sorted order, except for ...
5
votes
2
answers
251
views
Project Euler # 62 Cubic permutations in Python
The cube, 41063625 (\$345^3\$), can be permuted to produce two other cubes: 56623104 (\$384^3\$) and 66430125 (\$405^3\$).
In fact, 41063625 is the smallest cube which has exactly three permutations ...
5
votes
1
answer
62
views
Find amounts that cannot be composed using the given coins
I need to make a program that receives a set of currencies and tests which values between 1 and 10,000 units can not be produced with these currencies.
The program must have 2 input data:
The ...
5
votes
1
answer
1k
views
Dijkstra finding shortest path satisfying given constraints
The question is originated from Hackerrank.
Suppose there are 1 to N stores in a city which are connected by
bidirectional roads associated with traveling ...