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

learn more… | top users | synonyms (2)

-2
votes
1answer
33 views

“Finding possible candy permutations” HackerEarth challenge

Problem Statement Shil, Aditya and Utkarsh go to a candy shop. There are N candies present in the shop, which are indexed from 1 to N. All three of them select one candy to eat. ...
0
votes
0answers
15 views

Number of Chocolates to Gluttonize in Clojure

I’ve been dabbling in Clojure by solving programming puzzles. This particular puzzle is from HackerRank, with the objective of figuring out how much chocolate one could eat given three parameters: ...
-1
votes
3answers
67 views

Performing Operations on a List

Problem Statement (HackerRank) You have a list of integers, initially the list is empty. You have to process Q operations of three kinds: add s: Add integer s to your list, note ...
-6
votes
0answers
76 views

hackerrank CAMPERS: FINAL MATCH TO PLAY AS A COUNTER TERRORIST [on hold]

Problem Statement Time is running out. You have a final match to play as a counter terrorist. You have N players each having a distinct ID from 1 to N. You have to choose some players on your team ...
5
votes
2answers
138 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 ...
0
votes
1answer
232 views

Print the lexicographically smallest permutation that satisfies the given formation

Problem Statement: A DOTA game has N heroes, each with a distinct rank from [1..N]. In DOTA every formation is characterized as a permutation [1...N] of ranks of players. A formation is ...
2
votes
1answer
46 views

HackerRank Regex Challenge: Detect HTML Tags

Problem Statement In this problem you will use regular expressions to help you detect the various Tags used in an HTML document. Here are a few examples of tags: The "p" tag for ...
3
votes
1answer
235 views

Calculate pairs in a Set (“Sherlock and Pairs” HackerRank challenge)

I have started reading clean code and want to improve my coding practices. Here is my attempt at solving an online puzzle. Please review the code and let me know how could I have written it better in ...
7
votes
5answers
342 views

CodeEval Challenge: Remove specified characters from a string

Question Write a program which removes specific characters from a string. The first argument is a path to a file. The file contains the source strings and the characters that need to be ...
3
votes
0answers
26 views

Optimizing a problem that test all permutations of 1 array with other fixed array

I'm trying to solve this question on a contest programming judge. Description of the problem: There are N birds in a forest, each in their respective tree. There are N tired crows in this forest, ...
-4
votes
1answer
53 views

Return a sum unless one of the values is illegal

Is there a way to make my code more concise? Given 3 int values, a b c, return their ...
4
votes
1answer
53 views

Project Euler 42 - Finding triangle numbers

Here is my solution for Project Euler Problem 42, which is described in the following: The \$n^{th}\$ term of the sequence of triangle numbers is given by, \$t_n = ½n(n+1)\$; so the first ten ...
1
vote
3answers
171 views

Confirming existence of lapindromes

The following description is taken from CodeChef.com's Lapindrome problem. Lapindrome is defined as a string which when split in the middle, gives two halves having the same characters and same ...
2
votes
1answer
156 views

Ugly_Numbers Challenge

Is it understandable, how can the code be improved? And anything you think that may be helpful. Here is an example of challenge I try to solve. Edit: Thanks for advices how to make better ...
1
vote
1answer
71 views

SPOJ - POWFIB (Fibo and non fibo) Time Limit Exceeds

Problem Find (a^b)%M, where a = Nth non-fibonacci number b = Nth fibonacci number modulo M M = 1000000007 Consider fibonacci series 1,1,2,3,..... INPUT First line ...
4
votes
1answer
105 views

Counting number of inversions

This is a HackerEarth Challenge Problem. Question: Puchi hates to carry luggage, but unfortunately he got a job to carry the luggage of his N friends in office. Each day, one of his N ...
7
votes
2answers
181 views

Solving 'decent numbers' that follow specific division rules

HackerRank Problem Statement I have to find the largest 'decent number' having N digits. A decent number has the following properties: 3, 5, or both as its ...
10
votes
2answers
198 views

You need to diversify your strings

Challenge: Write a program which prints all the permutations of a string in alphabetical order. Specifications: Your program should accept a file as its first argument. The file contains ...
5
votes
3answers
70 views

Project Euler problem 92 (sequences formed by the sum of squares of digits) in Haskell

I made the following program in Haskell to solve Project Euler's problem 92. The program works (i.e. the solution it yields is correct), but it's not exactly the fastest in the world. The problem is: ...
3
votes
1answer
79 views

Detecting cycles

This is a challenge question from codeeval.com: Given a sequence, write a program to detect cycles within it. Input sample: Your program should accept as its first argument a path to a ...
7
votes
2answers
169 views

Complete “Is it simple or is it hard?” challenge from Code Golf

Having written C# for half a year now, I decided to take on a fairly complex first challenge for C++: the Is it simple or it is hard? challenge from Code Golf Stack Exchange. (This is only practice, ...
8
votes
2answers
341 views

These words are so dirty

Challenge: Write a program that will clean up the words from extra numbers and symbols. Specifications: The first argument is a path to a file. Each line includes a test case with a list ...
8
votes
2answers
77 views

Summing all numbers that can be formed from a list of integers

Following a challenge on HackerRank, I want to find the sum of all numbers that have no more than x 4's, y 5's, and ...
4
votes
2answers
33 views

Matasano CryptoPals Problem 8: Detecting ECB encryption

For the Matasano CryptoPals Challenges Set 1 Problem 8, which states: In this file are a bunch of hex-encoded ciphertexts. One of them has been encrypted with ECB. Detect it. ...
4
votes
2answers
48 views

Longest lines of file descending

This is a challenge question from codeeval.com: Write a program which reads a file and prints to stdout the specified number of the longest lines that are sorted based on their length in ...
8
votes
5answers
564 views

Find longest lines from a file

This is a challenge question from codeeval.com: Write a program which reads a file and prints to stdout the specified number of the longest lines that are sorted based on their length in ...
3
votes
3answers
65 views

Matrix class with lots of tiny methods

I have been following the advice to make tiny methods that does just one thing and does it well. I also have been keen on reducing or eliminating duplication as much as possible. But when a very ...
5
votes
2answers
42 views

The Geppy String: Regex vs Iteration

We'll say that a lowercase 'g' in a string is "happy" if there is another 'g' immediately to its left or right. Return true if all the g's in the given string are happy. ...
2
votes
2answers
66 views

ProjectEuler Problem #3

I'm working on projecteuler.net problems, and I made this for problem #3: ...
11
votes
2answers
346 views

Project Euler # 7 in C++

I attempted the Project Euler question #7 in C++ ("What is the 10 001st prime number?"). I took into account what I've been told about primes in order to create the most efficient algorithm I could ...
4
votes
1answer
72 views

Hackerrank regex solution

I solved the following problem on Hackerrank. The challenge is to: Parse HTML input and display the tags and attributes in lexicographically ascending order. This is the input format: ...
4
votes
4answers
864 views

Staircase problem solved using recursion

Problem Question taken from here. I want to go up a flight of stairs that has n steps. I can either take 1 or 2 steps each time. How many different ways can I go up this flight of stairs? Write a ...
4
votes
1answer
62 views

Balancing words

A word is balanced at the index if the sum of the alphabet positions of all the chars multiplied by the distance to the index is zero. This description is equivalent to the one given by ...
2
votes
2answers
81 views

DailyProgrammer Balancing Words Challenge

I'm hoping for someone to help me use the best practices and further make my code better that I used to accomplish the DailyProgrammer Challenge "Balancing Words". The challenge is to check if a word ...
4
votes
2answers
158 views

Program to solve variations of the seven thieves & diamonds riddle

I answered a question yesterday on SO based on this riddle, but the code was so hard to read/follow to actually understand what was going on it was easier to write my own code to test the scenario and ...
4
votes
2answers
212 views

Project Euler Problem 5

I wrote up a small script to calculate the answer to Project Euler Problem 5: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What ...
6
votes
2answers
100 views

Project Euler #3

I wrote some code to solve this question and I was wondering if it was efficient or not. I just started learning code last week and I would like to get some input so I can get in the habit of writing ...
11
votes
2answers
356 views

Word Morph (changing one letter at a time)

Below is my implementation of Word Morph solver in Python. The challenge consists of transforming one word into another word by changing one letter at a time. Each word in the chain should be an ...
5
votes
2answers
122 views

“Algorithmic Crush” problem hitting timeout errors

This is the HackerRank problem Algorithmic Crush: You are given a list of size N, initialized with zeroes. You have to perform ...
7
votes
1answer
157 views

GCD using Euclid algorithm

Below is the problem taken from here. Question 10: GCD* The greatest common divisor of two positive integers a and b is the largest integer which evenly divides both numbers (with no ...
5
votes
2answers
95 views

Text justification

This is the Text Justification challenge at LeetCode: Given an array of words and a length \$L\$, format the text such that each line has exactly \$L\$ characters and is fully (left and right) ...
3
votes
0answers
21 views

Project Euler #2 in Go

I just learned Go (yesterday in fact) and today I made this solution to Project Euler #2. The problem is to sum the even Fibonacci numbers. My program uses the matrix representation of the linear ...
2
votes
1answer
51 views

Concurrency Bank exercise with multiple accounts

I am doing an exercise in Java concurrency. The problem statement is as follows: Bank holds an array of Accounts. Client do (in a loop) the following operations: (1) work, then sleep for random ...
4
votes
2answers
88 views

Project Euler - Problem 54: testing poker hands

This was a very fun and thought provoking problem, and I'm quite proud of the way I was able to pull it off. I broke it down into 2 parts, testing and comparing. Testing each group of cards for ...
4
votes
2answers
93 views

Even Fibonacci numbers under 4,000,000 (Project Euler #2)

Prompt: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, ...
3
votes
2answers
104 views

Euler 357 solution efficiency

I have a Ruby program which should solve the following problem: Consider the divisors of 30: 1,2,3,5,6,10,15,30. It can be seen that for every divisor d of 30, d+30/d is prime. Find the sum ...
5
votes
2answers
83 views

Finding the sum of all the multiples of 3 or 5 below any given number

I wrote the following simple function in JavaScript that finds the sum of all the multiples of 3 or 5 below a value, given from a text-box. I have used \$\dfrac{n}{2(a_1 + a_n)}\$ (sum of arithmetic ...
3
votes
1answer
52 views

Keeping just the rare characters in a long string

I'm working on The Python Challenge. The current code iterates over a 98,766-character string before printing an 8-character string. Current execution time is between 7 and 10 seconds. How can I ...
3
votes
1answer
79 views

Project Euler 348: Sum of a square and a cube

Many numbers can be expressed as the sum of a square and a cube. Some of them in more than one way. Consider the palindromic numbers that can be expressed as the sum of a square and a cube, ...
4
votes
5answers
289 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 ...