13
votes
5answers
740 views

Tape Equilibrium

I picked the first test (Tape Equilibrium) from Codility here. Question: A non-empty zero-indexed array A consisting of N integers is given. Array A represents numbers on a tape. Any integer ...
12
votes
1answer
543 views

Project Euler “Even Fibonacci numbers” in Java 8

I'm looking for general advice on my code on the following problem: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 ...
11
votes
4answers
406 views

Suggestions for improvement on Project Euler #7

Here is a solution for Project Euler Problem #7. By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10,001st prime number? I've ...
10
votes
2answers
6k views

Problem 5 on Project Euler

I just recently learned about Project Euler and have started doing the problems on there. I cleared problem 1 and 2, had no idea how to do 3 and 4, and started to do 5. I've seen the post regarding ...
10
votes
3answers
798 views

Codility - Perm-Missing-Elem: 100% functional score, but only 60% performance

I can not figure out why I didn't get 100% success from the Codility's Perm-Missing-Element test even I solve with \$O(n)\$. I will appreciate any advice/answers. You can see the problem, my code, ...
10
votes
3answers
207 views

Project Euler “Largest prime factor” (#3) in Java

The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? I wrote the following code with help of some Java 8, I'll explain the equivalent ...
9
votes
2answers
472 views

'Team Split' problem

Below is my solution for this 'Team Split' problem. In summary, the problem is to find relative strength of 2 teams by finding the difference between their total strength (individual strengths can be ...
9
votes
3answers
759 views

Checking brackets nesting in a string

I took a training challenge on Codility that checks for the proper nesting of brackets in a string. The brackets to be checked are {,},(,),[,]. I have written the ...
9
votes
3answers
291 views

Optimizing “Herd Sums” problem using dynamic programming

I'm trying to solve a practice problem and all is well except for the last 2 inputs my solution is too slow. Just one loop is slowing it down I think. Herd Sums Execution Time Limit: 2 ...
8
votes
4answers
231 views

PUT (Parallel Universe Time) generator

I don't like to post programming contest code in here, but I really like the question and want to share it with you all. It has been years since Superman started his enmity with the super-genius ...
7
votes
5answers
524 views

Spotify Cat vs. Dog Challenge

I implemented an algorithm to solve a constraint satisfaction problem. It is a non-trivial one, so I do not intend to take your time with its details. I am mainly looking for good code suggestions ...
7
votes
5answers
484 views

Ten thousand and first prime checker takes a very long time

I am attempting problem 7 on Project Euler. I have come up with this solution which works fine for finding smaller nth prime numbers, but really lags when it comes to higher nth prime numbers. I am ...
6
votes
3answers
530 views

Codility Frog Jump - Count minimal number of jumps from position X to Y

Here is a question I tried from the Codility train website: A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position ...
6
votes
2answers
210 views

Finding the count of all repeats in an array of integers

The problem is about finding the sum of all repeating groups from an integer array as explained below and here Problem statement: Say that a "clump" in an array is a series of 2 or more adjacent ...
6
votes
1answer
257 views

Finding the largest mirror image of a subset/set of integers present in an array of integers

The problem I am talking about is this. Problem statment: We'll say that a "mirror" section in an array is a group of contiguous elements such that somewhere in the array, the same group ...
5
votes
6answers
310 views

Speeding up my implementation of Project Euler #3

Project Euler problem 3 asks for the largest prime factor of 600851475143. I have gone from 96 lines to 17 lines taking hits at this one. This is what I am left with after all of that effort: ...
5
votes
2answers
169 views

“Chef and Digits” Java solution

I am looking for a review on the following code which is for this question. I am looking for a general review of the code. I am specifically also looking for advice on how to make this code run more ...
5
votes
2answers
2k views

Finding the most common character in a string

I have started to try and work out the TopCoder problems. The "StringDup" problem asks us to: Create a class called StringDup. Given a string made up of ONLY letters and digits, determine which ...
5
votes
3answers
77 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
1answer
86 views

Calculate difference of indices

The challenge is to reconstruct an n-digit number using the following information: On each step, you choose an index x from 1 to n. For all indices y (y < x), you calculate the difference by ...
4
votes
2answers
289 views

k_diff challenge in Java

Puzzle Description Given \$N\$ numbers, \$N <= 10^5\$, count the total pairs of numbers \$(N_i, N_j)\$ that have a difference of \$K = N_i - N_j\$ where \$0 < K < 10^9\$. Input ...
4
votes
2answers
127 views

Rotating the string optimization

Below is the code for the problem at Codechef. I have made use of the String method .equals in my solution which is working fine ...
4
votes
2answers
171 views

Project Euler “Largest product in a grid” (#11) in Java 8

I have come up with a Java 8 solution for the following problem: In the 20×20 grid below, four numbers along a diagonal line have been marked in red (bold here). 08 02 22 97 38 15 00 40 00 75 ...
4
votes
2answers
674 views

Determining possible triangle from lengths of line segments [closed]

This Codility challenge is to take an array of integers representing lengths of line segments, and determine whether or not it is possible to choose three distinct segments to form a triangle. (The ...
4
votes
1answer
112 views

Google Code Jam 2014: Full Binary Tree

Here is my entry for the Code Jam problem Full Binary Tree (I didn't compete but tackled the problem afterwards). It does solve the provided inputs, so I suppose it is correct. I am looking for any ...
4
votes
1answer
349 views

Binary Tree Level Order Traversal Algoritm

I am trying to solve this Binary tree lever order traversal ...
3
votes
2answers
757 views

Rot -n algorithm in Java

This is a rot-n (rotate n times) encrypt/decrypt algorithm, where n can be any integer (+/-). It's written to encrypt/decrypt all the alphabets (upper/lower case) and leaving behind all non-alphas. ...
3
votes
2answers
268 views

Project Euler problems 18/67: maximum path sum

I recently solved problems 18/67 in Project Euler. My code is long and I think it could be more effective. I solved the problem with dynamic programming and am new to it, so I want to improve my ...
3
votes
3answers
536 views

Smallest prime factor of a large number (using BigInteger)

I'm working on a Project Euler problem and am trying to get the smallest prime factor of a BigInteger: ...
3
votes
2answers
215 views

Python vs. Java Runtime on Euler 22

On performing the following Euler problem, Python takes up less lines and runs faster (Python ~0.05s, Java ~0.3s on my machine). Could I optimize this Java code in any way? The problem is here ...
3
votes
1answer
182 views

Hackerrank - Sherlock and the Beast

I am trying to solve the Sherlock and The Beast HackerRank challenge. Most tests timeout, however when I try a custom stretch test case (T = 20 and all N = 100000), it returns successfully, so I'm not ...
3
votes
1answer
427 views

Decoding binary string message

I am trying to learn some Java on my own, and I am tackling some "programming challenge" problems to practice the little I have learnt so far. Could anybody constructively critique this beginner's ...
2
votes
2answers
1k views

Fish Food Chain O(N)

I understand that if you don't know the trick, it's not easy create a solution with a complexity of O(N). However, I would like to ask you how to solve this tricky question: You are given two ...
2
votes
3answers
503 views

Project Euler Problem #3 - largest prime factor

I have began doing the problems found on Project Euler and have just solved problem 3. However, I feel as if my code is very long and too brute-force. I was hoping somebody could give it a look and ...
2
votes
2answers
1k views

Enormous Input Test - reducing program runtime

This is my solution to SPOJ Problem 442. How can I make this code run faster? What are some techniques that can be used to make this faster? I am getting a Time Limit Exceed Error here. ...
2
votes
2answers
1k 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 ...
1
vote
3answers
128 views

Optimize calculation of distances between pairs of points

I was trying to solve a challenge. The execution time should not exceed 5s, but for some value my code took longer. I want to know if I can optimize my code for performance. ...
1
vote
4answers
3k views

Need a faster way to determine largest prime factor

Project Euler problem 3 asks: What is the largest prime factor of the number 600851475143? The first step I took is to determine the highest value number I should be looking at as a possibility ...