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

learn more… | top users | synonyms (2)

0
votes
1answer
26 views

Project Euler problem 31 - tail recursive algorithm [on hold]

In Scala, a recursive algorithm for project Euler problem 31 is the following: ...
3
votes
1answer
30 views

Codility Frog Jump solutions

Problem details from Codility: 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 greater than or equal to Y. The ...
2
votes
2answers
25 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 ...
8
votes
1answer
54 views

Ugly Numbers: A Rags-to-Riches Story

I stumbled upon an unaswered question, which looked like a good fit for a functional programming language. Here is the problem statement from codeeval: UGLY NUMBERS CHALLENGE DESCRIPTION: ...
3
votes
2answers
76 views

Timing Project Euler Problem 1

Is there a better way to time the functions and print the result and function name dynamically? ...
2
votes
1answer
75 views

Painting Fences - optimize for faster performance

I am attempting this problem at Codeforces. I'm stuck as it gives a time limit exceeded error for large inputs though the logic I followed is similar to that of the editorial. I'd be grateful for any ...
7
votes
2answers
89 views

TapeEquilibrium implementation does not satisfy all requirements

The Codility's TapeEquilibrium problem asks: Given an array \$A\$ with length \$N\$, indexed starting from 0, find an equilibrium index \$P\$, such that $$\left| \sum_{i=0}^{P-1} a_i - ...
5
votes
5answers
95 views

Improving efficiency for two sum

I am trying to solve this problem: Given an array of integers, find two numbers such that they add up to a specific target number. and this is my strategy: For each ...
4
votes
3answers
121 views

Modified Sieve of Eratosthenes has very long runtime

I am slowly moving through Project Euler, and have reached problem #10: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. I did a naive ...
-1
votes
0answers
78 views

Game of hog in Python

Below is the problem statement for Hog: In Hog, two players alternate turns trying to reach 100 points first. On each turn, the current player chooses some number of dice to roll, up to 10. She ...
6
votes
1answer
108 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 ...
1
vote
1answer
48 views

Application of higher-order function in Python

If \$f\$ is a numerical function and \$n\$ is a positive integer, then we can form the \$n\$th repeated application of \$f\$, which is defined to be the function whose value at \$x\$ is ...
3
votes
1answer
68 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 ...
21
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 ...
3
votes
1answer
117 views

Speeding up Codechef FROGV

This is my solution to the FROGV problem on Codechef: ...
2
votes
1answer
96 views

Sum the Multiples of 3 and 5

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below N. ...
-2
votes
1answer
50 views

hailstone sequence using recursion in python

Douglas Hofstadter's Pulitzer-prize-winning book, Gödel, Escher, Bach, poses the following mathematical puzzle: Pick a positive integer n as the start. If n is even, divide it by 2. If n is ...
6
votes
2answers
78 views

Time Limit Exceeded with Segment Tree data structure

I am trying to solve this problem Chef Ceil has some matchsticks in his kitchen. Detail of matchsticks: There are N matchsticks in total. They are numbered from to 0 to N-1 inclusive. ...
3
votes
2answers
125 views

Building a list - why is this code inefficient?

I'm attempting this code challenge. Here's my code modified to handle one simple example test case: ...
5
votes
1answer
61 views

Project Euler code evaluation - digit fifth powers

This is for Project Euler #30: Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits: \$1634 = 1^4 + 6^4 + 3^4 + 4^4\$ \$8208 = 8^4 + ...
3
votes
1answer
113 views

Minimum number of letters removed, to make a string Peragram

Here is the link to the problem Peragrams. Peragrams: If a word is an anagram of at least one palindrome, we call it a Peragram. Problem: Given a string, find the minimum number of letters ...
4
votes
1answer
33 views

Basic Reverse Polish CL Parser

K and R Exercise 5-10 Write the program expr, which evaluates a reverse Polish expression from the command line, where each operator or operand is a separate argument. For example, ...
5
votes
3answers
122 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 ...
11
votes
3answers
887 views

The Love-Letter Mystery

Problem Statement James got hold of a love letter that his friend Harry has written for his girlfriend. Being the prankster that James is, he decides to meddle with it. He changes all the ...
6
votes
2answers
233 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 ...
1
vote
2answers
47 views

Skiena's Programming Challenges: The Trip problem

I have the following solution for the Trip problem from Skiena's and Revilla's Programming Challenges (full problem description here). ...
6
votes
1answer
289 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
96 views

Largest Prime Factor redux

There have been a number of questions asking for comments on code for the Project Euler problem to compute the largest prime factor of a number. A primary intent of this task is to find the factor as ...
2
votes
1answer
73 views

Typeahead Talent Buddy

Problem is Talent Buddy. Your task is to write a function that prints to the standard output (stdout) for each query the user name that matches the query if there are multiple user names ...
10
votes
1answer
302 views

x64 Assembly - checking for largest prime factor

Using x64 assembly, I solved the Largest Prime Factor problem on Project Euler. The problem is as follows: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of ...
2
votes
1answer
58 views

Performance of Codility MaxCounter challenge solution

I'm doing some of the Codility challenges using Ruby. The current challenge is "The MaxCounter," which is described as: Calculate the values of counters after applying all alternating operations: ...
4
votes
0answers
41 views

Project Euler Problem 18 (Haskell) - Maximum path sum I

I've implemented the solution to Project Euler Problem 18 in Haskell and I'd like to get some thoughts on my implementation. Its the dynamic programming solution, working from the bottom up. ...
6
votes
1answer
53 views

Implementing a data structure that is a collection of sets

I'm trying to optimize my code (time optimization) based on this problem: Let S be a set of strings. Each string in S is ...
6
votes
2answers
378 views

Stack challenge - improving memory consumption

I am working on this problem: Stacks Imagine, that you are employed by a software development company. You work now on the famous "D++ project", which is devoted to the creation of a new ...
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 ...
10
votes
1answer
145 views

Tweets per second, using linked list

This is a TalentBuddy Challenge Your task is to write a function that prints to the standard output (stdout) the highest number of tweets recorded between each second in the array and the past ...
3
votes
1answer
45 views

Adding reversed numbers

This is my solution to the competitive coding question on SPOJ here. It gives a runtime of 0.24 but the best solutions posted have a 0.0 runtime. How could I possibly achieve better results than ...
4
votes
3answers
146 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
2answers
100 views

Typeahead autocomplete functionality challenge

I'm working on a Talent Buddy challenge . In this challenge you have to design the autocomplete functionality of Twitter. You are given a list of queries and possible usernames. You have to return the ...
4
votes
3answers
69 views

String self-similarity

It's a string problem I have been making on Hackerrank. It is executing fine on all test cases except the last two. These last two test case are declaring it "Terminated due to time out". C programs ...
5
votes
3answers
88 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 ...
14
votes
6answers
2k views

Sherlock and The Beast

This is my solution to this question from Hackerrank. Given N (<= 100000), find the largest N-digit number such that: The number has only 3 and 5 as its digits. Number of times 3 ...
6
votes
5answers
522 views

Improving efficiency of Project Euler 185 (16-place Mastermind)

This a solution for Project Euler Problem 185. It works fine for the example but slow for the problem statement. How can I improve its speed and efficiency? ...
4
votes
1answer
77 views

Dynamic programming with Project Euler #18

I just wanted to get an opinion on my dynamic-programming Haskell implementation of the solution to Project Euler problem 18. The Problem: By starting at the top of the triangle below and moving ...
7
votes
4answers
422 views

Checking if a number is a perfect square by recursive sum of its digits [closed]

I was solving this question on an online judge. The problem boils down to the following: Given a number \$n\$, where \$1 \le n \le 10^{18}\$, we need to check if it contains odd number of ...
11
votes
7answers
2k views

Is my solution to return kth row of the Pascal's triangle suitable for a job interview?

Question: Given an index \$k\$, return the \$k\$th row of the Pascal's triangle. For example, given \$k = 3\$, return \$[1,3,3,1]\$. Bonus points for using \$O(k)\$ space. Can it be ...
2
votes
1answer
51 views

Two squares or not two squares - constant time optimization

I have been trying to solve this problem, and after a bit of googling, I realised a \$O(\sqrt{n})\$ time complexity works fine (though the algorithm suggested is different from that I have used). My ...
4
votes
1answer
254 views

Hackerrank Gem Stones

I am working on some problems on Hackerrank. John has discovered various rocks. Each rock is composed of various elements, and each element is represented by a lowercase Latin letter from 'a' to ...
4
votes
3answers
153 views

Penney Game - mapping macros to strings

The SPOJ problem: Given a 40 character string representing outcomes of 40 coin tosses, find the frequency destribution of all the possible outcome triplets. So, for string like : HHHH....40 Hs ...