Tagged Questions
3
votes
1answer
57 views
Determining maximum profit to be made from selling shares
Question
Your algorithms have become so good at predicting the market that you
now know what the share price of Wooden Orange Toothpicks Inc. (WOT)
will be for the next \$N\$ days.
...
2
votes
2answers
37 views
Calculating the number of prime numbers to solve the puzzle
How can the following program execution time improved? I have used dynamic programming in both "recursive" as well as "prime" function, but I'm not getting the efficient execution time.
There is ...
6
votes
1answer
109 views
Finding common strings among 2 arrays of strings of length 1, sorted alphabetically in O(n) time complexity
The problem:
Start with two arrays of strings, a and b, each in alphabetical order,
possibly with duplicates. Return the count of the number of strings
which appear in both arrays.
...
11
votes
2answers
138 views
100 gunmen in circle kill next person
The question is here.
100 people are standing in a circle with gun in their hands. 1 kills 2, 3 kills 4, 5 kills 6 and so on till we are left with only one person. Who will be the last person ...
3
votes
1answer
71 views
Finding if there is a subset that sums to a target value from an array of integers
I came across this problem.
Problem Statement:
Given an array of ints, is it possible to choose a group of some of
the ...
22
votes
8answers
2k views
The FizzBuzz challenge in Java 8 written in a short, readable and interesting way
I decided to take on the FizzBuzz challenge with as twist that I would use Java 8 concepts to make it a bit modular, yet still let it be a short, readable and understandable program.
This in contrary ...
6
votes
2answers
237 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
290 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 ...
7
votes
2answers
362 views
Optimizing this inefficient TicTacToe configuration parser
On a programming contest I came upon this question:
Given a partially played 3 × 3 tic-tac-toe configuration, write a program to determine which player will have a better chance of winning if the ...
5
votes
3answers
91 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 ...
3
votes
2answers
279 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 ...
4
votes
1answer
114 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 ...
9
votes
3answers
312 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 ...
1
vote
1answer
58 views
GSS1 SPOJ problem Time Limit Exceeding
The problem is presented here as follows:
You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1
≤ N ≤ 50000 ). A query is defined as follows: Query(x,y) = Max {
...
4
votes
2answers
151 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 ...
10
votes
3answers
1k 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, ...
3
votes
1answer
232 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 ...
6
votes
3answers
718 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
172 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
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
1answer
433 views
Binary Tree Level Order Traversal Algoritm
I am trying to solve this Binary tree lever order traversal
...
9
votes
2answers
473 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 ...
7
votes
5answers
487 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 ...
13
votes
5answers
828 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 ...
5
votes
6answers
311 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:
...
4
votes
2answers
183 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 ...
10
votes
3answers
230 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 ...
13
votes
1answer
616 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 ...
9
votes
3answers
887 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 ...
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 ...
3
votes
3answers
567 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:
...
6
votes
2answers
634 views
Fizz Buzz Bizz Fuzz in Java
This questions is originally from http://contestcoding.wordpress.com/2013/06/28/fizz-buzz-bizz-fuzz/.
Print the integers from 1 to 100,
but for the multiples of 3, print "Fizz" instead and
...
11
votes
4answers
413 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 ...
8
votes
4answers
243 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 ...
4
votes
2answers
704 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 ...
2
votes
2answers
2k 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 ...
7
votes
5answers
551 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 ...
1
vote
3answers
130 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.
...
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 ...
2
votes
3answers
600 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 ...
0
votes
2answers
1k views
Spotify's “Reversed Binary Numbers” Problem [closed]
I wrote some Java code for Spotify's Reversed Binary Numbers puzzle and I tested it on my machine and I am almost positive that it behaves as expected. However, when I send it to puzzle AT spotify.com ...
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 ...
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.
...
3
votes
1answer
433 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 ...
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 ...
2
votes
1answer
170 views
Spotify Best Before puzzle
I thought to spent my free time by solving a puzzle: Best Before Spotify Puzzle.
I coded in Java, and yeah I did not clean up my code (just a rough work) and I have yet to optimize... so I did check ...
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
363 views
Changing bits in given big strings
I came up with this question.
Let A and B be two N bit numbers. You are given initial values for A and B, and you should write a program which processes three kinds of queries:
set_a idx x: ...
4
votes
2answers
295 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 ...
3
votes
2answers
773 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.
...