Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.

learn more… | top users | synonyms (2)

1
vote
2answers
25 views

Project Euler problem 23 - non-abundant sums

I present my solution for Project Euler problem 23 written in Python (2.7). The problem statement is: A perfect number is a number for which the sum of its proper divisors is exactly equal to ...
0
votes
1answer
17 views

Converting string elements of an array to upper and lower case, maintaining names of keys

I'm just going through some array exercises in PHP on w3resource. I have just completed: Sample array : ...
1
vote
1answer
55 views

Optimizing my solution for problem #23 - project Euler

The question - 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 proper divisors of 28 would be 1 + 2 + 4 + 7 + ...
2
votes
2answers
181 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 ...
2
votes
0answers
60 views

Find largest rectangle

I solved this challenge and it passes all the test cases. Problem Statement There are N buildings in a certain one-dimensional landscape. If you join K adjacent buildings, they will form a ...
4
votes
3answers
368 views

Finding the average, the five smallest, and the five largest numbers in an array

I am going though some PHP arrays exercises on w3resource. I have just completed the following: Write a PHP script to calculate and display average temperature, five lowest and highest ...
-1
votes
0answers
27 views

Algorithm PHP - Optimize code for finding minimum array integer

Im trying to solve one simple task and on first look it is working. Every advice how I can optimize this code will be precious. So one fast description of the task : You have a file from which you ...
-1
votes
1answer
15 views

Sorting an array in different ways with efficient output

I am going through some PHP array exercises on w3resource because I want to get to grips with all the different functions PHP offers for arrays. I have just done this one: Write a PHP script to ...
3
votes
2answers
44 views

Search key in a rotated sorted array without repetition of elements

Is there any improvement possible in this implementation? //Search in sorted rotated array ...
4
votes
3answers
318 views
3
votes
1answer
65 views

Project Euler #10 and #12 in Java - Prime Numbers

I am dealing with a huge time taking with primes. I hope you know they are pretty random and that's why create many problem. Both are using the same logic/methods. ...
3
votes
1answer
40 views

HackerRank challenge - index palindrome

I have a solution but it fails the performance for two tests. How can I speed it up? ...
8
votes
3answers
692 views

Project Euler #4 - Largest Palindrome Product in Java

I am seeing that this is actually not in accord with the difficulty level said there. Firstly I cannot list all possible improvements it could have. ...
4
votes
1answer
95 views

Project Euler: Problem 22 (2 versions)

I wrote 2 versions of problem 22 on Project Euler: Using a text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value ...
1
vote
1answer
76 views

Project Euler Problem 11 (“Largest product in a grid”) in Python

Can this code in any way be improved or optimized? I'd appreciate any clever tricks or Pythonic expressions that may remove some more brute force elements from my solution. Also, is there possibly a ...
5
votes
3answers
73 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 ...
4
votes
1answer
91 views

Password Attacker (Google apac test problem)

Original Problem Short Summary: Given a \$M\$ possible characters all of which must be used at least once, find the number of possible combinations of length (exactly) \$N\$. The ...
5
votes
1answer
43 views

Optimal way to annihilate a list by removing items from the ends

I'm stuck with a contest problem. Description: What is the minimum number of moves to annihilate an int array where the possible moves are: Remove both the first and last elements if they are ...
7
votes
3answers
244 views

Google Foobar Challenge: Save Beta Rabbit in Python

I'm going through the Google Foobar challenges and am currently on the first challenge of level three. I've come up with a working solution, however, it's not an acceptable solution because it runs ...
4
votes
0answers
36 views

BotClean challenge

I'm going through the artificial intelligence domain at HackerRank. I'm very new to this domain and I really need a guide on how should I minimize the number of ...
0
votes
0answers
26 views

Finding prime numbers in the range (m,n) [closed]

Problem : Find all prime numbers in the range (m,n). Input : No. of Test cases, m, n. Eg. 2 1 10 3 5 Output : Primes (m,n) Eg. 2 3 5 7 3 5 Here is my code : ...
-1
votes
0answers
11 views

SPOJ giving WA for this dynamic programming approach for FPOLICE [closed]

I have been struggling a lot with this problem on SPOJ. I am using a DP approach. I am able to get the correct answer for all the test cases but am still getting WA on SPOJ. I have checked at least ...
3
votes
3answers
61 views

Minimum Value evenly divisible by all integers from 1 to n

I have just started learning python and I am solving Project Euler problems alongside for practice. This is my solution for problem 5. Project Euler asks for the minimum value divisible by all numbers ...
5
votes
1answer
77 views

Super2048 (Google apac Test Problem)

This is my second try at writing Ruby. Stylistic feedback is very much appreciated. The problem: 2048 is played on a simple 4 x 4 grid with tiles that slide smoothly when a player moves them. ...
5
votes
2answers
74 views

Project Euler #9 in C: Special Pythagorean triplet

I have finished Project Euler #9 on HackerRank: Given \$N\$, Check if there exists any Pythagorean triplet for which \$a+b+c=N\$, \$a^2+b^2=c^2\$. Find maximum possible value of \$abc\$ among ...
4
votes
3answers
102 views

Print the number of unique pairs Stored in a HashSet

I'm trying to solve this fairly straight forward challenge: Problem Statement In computer science, a set is an abstract data type that can store certain values, without any particular ...
2
votes
1answer
29 views

SPOJ “SBANK - Sorting Bank Accounts” TLE

I am new tro programming and have chosen python 2.7 to begin with. But, I often have to deal with a TLE while competitive coding like in the problem below, where my code runs fine on all test cases ...
0
votes
2answers
60 views

Improving code with loops in Java [closed]

I am working in a lemonade stand game in Java I have some conditions to determine the "perfect recipe" I see a lot of repeated code that I am sure it can be improved with a loop but I am having a hard ...
1
vote
1answer
47 views

Lemonade Game in Java [closed]

I am writing the lemonade stand game in Java but I am having a bit of trouble trying to figure out the perfect recipe. I have most of the code done, except the math logic seems a little off. Please ...
2
votes
3answers
59 views

SPOJ “To and Fro”

This is the To and Fro problem at SPOJ: Mo and Larry have devised a way of encrypting messages. They first decide secretly on the number of columns and write the message (letters only) down the ...
5
votes
1answer
63 views

Sort a scrambled itinerary (Google apac test problem)

This is my first time writing ruby - and I was mainly hoping to get some feedback and stylistic pointers. The algorithm is pretty straight-forward, since Google guarantees airports aren't repeated I ...
4
votes
2answers
120 views

Finding all the subsets in an array of integers that sum to a given target

Problem Statement: Given an Array if ints, Find out all the subsets in the Array that sum to a given target value. Example: If the input array is: ...
7
votes
2answers
100 views

Project Euler #1 in Haskell

Looking for feedback/critiques/alternatives to my solution for the 1st Project Euler question: ...
6
votes
0answers
88 views

Martian Robots - a small JS program

Please look at a small piece of code I wrote and provide some thoughts, critiques and any feedback you think is needed. The code is here along with the problem I have attempted to solve and I look ...
6
votes
4answers
519 views

Euler #3 largest prime factor

Problem Statement This problem is a programming version of Problem 3 from projecteuler.net The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of a given number ...
3
votes
1answer
75 views

Project Euler #5 - Smallest Multiple

JavaScript is my first programming language, and I'm still pretty new. I'm just looking for feedback. What can I do to make this more efficient and handle larger numbers? ...
3
votes
1answer
44 views

Integer ID pool

I would really appreciate some feedback on the code I wrote to solve the following problem: Design an IdManager. IdManager manages a pool of integer ids. (from 1 to n). It should provide ...
3
votes
0answers
35 views

Equivalent binary trees (A Tour of Go)

Any suggestions on how to improve the code shown below for the Go-tour exercise? Exercise description: There can be many different binary trees with the same sequence of values stored at the ...
0
votes
0answers
33 views

HTTP handlers exercise (tour of go)

Any suggestions on how to improve the code shown below for the go-tour exercise http://tour.golang.org/methods/14? Exercise description: Implement the following types and define ServeHTTP methods on ...
-3
votes
0answers
48 views

A Tour of Go: rot13reader

Any suggestions on how to improve the code shown below for the Go-tour exercise? Exercise description: A common pattern is an io.Reader that wraps another io.Reader, modifying the stream in ...
1
vote
1answer
35 views

Project Euler 22: Names Scores — With flowchart

Full text of the problem Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. ...
6
votes
3answers
270 views

For each line in a file, read two integers and output the minimum

I am going through some CodingAbbey problems to learn basic programming tasks, with a focus on taking input from a file, and saving to another. I have just completed this task: Of two numbers, ...
3
votes
2answers
128 views

FIZZ BUZZ -challenge program with adjustable intervals

This is again a solution to the codeEval challenge #1. It was accepted by codeEval, but please let me know if I can improve it anyway somehow? ...
4
votes
0answers
46 views

Longest (simple) path problem implementation for contest

For a seminar with problems from programming contests I have to implement an algorithm to find the longest path in a graph. Here is a short summary of what I want to solve/achieve: In this problem ...
2
votes
2answers
287 views

Project Euler #12 runs very slowly

The problem is : The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: ...
5
votes
4answers
278 views

Project Euler 50 in Python

Project Euler, problem #50: The prime 41, can be written as the sum of six consecutive primes: 41 = 2 + 3 + 5 + 7 + 11 + 13 This is the longest sum of consecutive primes that adds to a ...
3
votes
1answer
51 views

Necklace counting problem-with consecutive prime constraint

This is codeEval challenge to count the number of chains possible to make with beads holding numbers. Constraint is sum of the consecutive beads of chain should be a prime number. The standard ...
8
votes
2answers
789 views

Checking for any character common to two strings — Go is 50× slower than Python

I decided to learn Go, knowing Python. My approach is by solving easy problems like this one: You are given two strings, A and B. Find if there is a substring that appears in both A and B. ...
2
votes
2answers
171 views

Survivor programming challenge

I am working on a survivor problem: Complete Question Text: Take a second to imagine that you are in a room with 100 chairs arranged in a circle. These chairs are numbered sequentially from ...