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

learn more… | top users | synonyms (2)

1
vote
1answer
30 views

CodeChef- Chef and Strange Formula

For positive integer x let define function F(x) = 1 * (1! + x) + 2 * (2! + x) + .. + x * (x! + x). "k!" means factorial: k! = 1 * 2 * .. * k Chef wants to calculate F(p1) + F(p2) + ... + ...
5
votes
3answers
199 views

Using recursion to count substrings (with exceptions to the rule) in Java

I am going through the CodingBat exercises for Java. Here is the one I have just finished: Given a string, compute recursively the number of times lowercase hi ...
4
votes
2answers
240 views

Euler Project 12# - Inefficient Java Code

I'm an amateur programmer, new to Java and while attempting the Project Euler Archive 12 (Highly divisible triangular number) I ran into extremely long run time, with no result as of yet. My question ...
3
votes
1answer
25 views

Find the common elements of the lists in a list of lists

Considering the problem: Make a function to find the common elements of the lists in a list of lists. Example: common ( [ [1,2,3,3,5,11], [2,2,2,3,3,5], [2,2,3,3,4,5,6,7,18,19], ...
1
vote
1answer
36 views

Check if two strings are anagrams - HackerEarth

You are given two strings. You have to check if the strings are permutations of each other and output "YES" or "NO" accordingly without quotes. Input: 2 lines of input each containing a ...
-4
votes
0answers
23 views

Finding the least 3 values of an array? [on hold]

You are required to manage the sales data of a car showroom. There are 8 salesman. At the end of the month you have to make a report. You are required to make the following calculations.Input the ...
3
votes
1answer
43 views

HackerEarth: Find array index with cumulative sum till there matching a given target

The problem was like this: Given an array: [1, 2, 1, 3, 4] where each index value shows the production of that particular day. So, at index ...
4
votes
1answer
51 views

Finding common elements, ignoring duplicates, in two given string arrays

I am going through the CodingBat exercises for Java. Here is the one I have just completed: Start with two arrays of strings, a and ...
2
votes
1answer
44 views

Replacing all occurrences of a substring in a string without using regex

Problem Statement: Given two strings, base and remove, return a version of the base string where all instances of the remove string have been removed (not case sensitive). You may assume that ...
0
votes
3answers
47 views

SPOJ problem - The last digit of a number to a power (follow up)

As a follow up to my post here. Please refer to the problem statement in that post. I have edited this code to make it time efficient, but doing so the size of the source file has crossed the limit ...
1
vote
1answer
41 views

SPOJ problem - The last digit of a number to a power

Here is the problem statement: Given integers \$a\$ (\$0 \le a \le 20\$) and \$b\$ (\$0 \le b \le 2,147,483,000\$), where \$a\$ and \$b\$ are not both 0, find the last digit of \$a^b\$. ...
3
votes
0answers
31 views

Project Euler #10 in Ruby - summation of primes

I'd like to have some feedback as to the performances of the algorithm. ...
1
vote
2answers
62 views

Creating an array length n * n, separating it into n groups, and adding numbers to it n times

I am completing the CodingBat exercises for Java. Here is the one I have completed just now: Given n > = 0, create an array length ...
5
votes
2answers
89 views

Consecutive Primes challenge at CodeEval.com and memory allocation issue

I finally solved this challenge with using recursion and figured out why the automatic scorer wasn't passing my previous solutions. I was using NSMutableArray to ...
1
vote
2answers
48 views

arrayHistogram implementation

I wrote this code, called arrayHistogram, that would generate a random number within a set range, and print it in an array ...
7
votes
4answers
192 views

Identifying array elements, rearranging them, and replacing them

I am completing the CodingBat exercises for Java, and, having learnt from the answers to the previous one, I completed the one that follows: Return a version of the given array where all the ...
5
votes
3answers
232 views

Rearranging array elements depending on their indexes

I am (still!) going through these CodingBat exercises for Java. Here is the one I have just done: Return an array that contains the exact same numbers as the given array, but rearranged so that ...
2
votes
1answer
41 views

Hackerrank, Service Lane in Haskell

Problem statement Calvin is driving his favorite vehicle on the 101 freeway. He notices that the check engine light of his vehicle is on, and he wants to service it immediately to avoid any ...
12
votes
2answers
389 views

Split string in half and change case accordingly

I found the following challenge online: Create a function that takes a string and returns that string with the first half lowercased and the last half uppercased. eg: ...
1
vote
1answer
104 views

Consecutive Primes challenge at CodeEval.com

I am working through a new challenge on CodeEval.com and I think I am getting a correct result but I can't get through their grader. I am not exactly sure where error is. I didn't post this on stack ...
5
votes
2answers
206 views

Printing the n'th prime numbers

This is an online problem. The challenge is to print the kth prime number, for each k given in the input (1 ≤ k ≤ 15000). The first line of input indicates the number of inputs on the subsequent N ...
1
vote
2answers
34 views

Identifying numeric substrings of an alphanumeric string, and summing them

I am going through the CodingBat exercises for Java. Here is the task I have just completed: Given a string, return the sum of the numbers appearing in the ...
2
votes
2answers
29 views

Returning matching substrings, of n length, at the beginning and end of a string

I am going through the Java CodingBat exercises. Here is the one I have just completed: Given a string, return the longest substring that appears at both the beginning and end of the string ...
-1
votes
1answer
35 views

Locker puzzle in Python

(Game: locker puzzle) A school has 100 lockers and 100 students. All lockers are closed on the first day of school. As the students enter, the first student, denoted S1, opens every locker. ...
6
votes
4answers
358 views

Summing digits of an alphanumeric string

I am going through the Java CodingBat exercises. Here is the one I have just completed: Given a string, return the sum of the digits 0-9 that appear in the ...
4
votes
3answers
62 views

Case insensitively removing a substring, efficiently

I am going through the CodingBat exercises for Java. I have just completed this one: Given two strings, base and remove, ...
1
vote
2answers
92 views

HackerRank Sherlock and GCD challenge

I've written an implementation for the Sherlock GCD HackerRank Challenge. As the running time of my algorithm is something like O(kn^2), I reckon that there’s a more efficient algorithm that could be ...
8
votes
3answers
655 views

Find the next multiple of N that is a perfect square number

Given a number \$t\$, (\$1 \leq t \leq 1000\$) that represent testcases and \$t\$ numbers \$n\$ (\$1 \leq n \leq 10^9\$). Show the next multiple of \$n\$ that is a perfect square number. Example of ...
1
vote
4answers
95 views

Redacting everything in a string except a particular word

I am working through the Coding Bat exercises for Java. Here is one I have just completed: Given a string and a non-empty word string, return a version of the original String where all chars have ...
2
votes
1answer
88 views

HackerRank Grid Search challenge

I’ve written an answer for The Grid Search challenge on HackerRank. Please let me know of any improvements that can be made to my implementation (specifically if there's any way to make the algorithm ...
4
votes
3answers
62 views

Hackerrank, Utopian Tree in Haskell

Problem statement The Utopian tree goes through 2 cycles of growth every year. The first growth cycle occurs during the monsoon, when it doubles in height. The second growth cycle occurs ...
4
votes
3answers
869 views

Project Euler -problem 1

Find the sum of all the multiples of 3 or 5 below 1000. https://projecteuler.net/problem=1 Is there any hack to do modulo operation in better way? ...
2
votes
0answers
19 views

Dealing with input and output in Matlab

I just wrote a program which performed some elementary set operations as you can see below. It's the first time I have used input and output of text files so I am mainly looking for critique on that, ...
4
votes
2answers
120 views

HackerRank Angry Professor challenge

I've written an answer to HackerRank's Angry Professor problem. Please let me know if there's a quicker/better way of solving this as I think I wrote quite a bit of code for this problem (answer has ...
16
votes
1answer
4k views

100 gunmen in a circle kill next person

I am very happy because I solved this problem with very little code: ...
5
votes
1answer
294 views

Left Shifting an array of ints

The problem I am referring to is here So basically it's about shifting an array of ints 1 position to the left and relocating the lost first int in the start of ...
2
votes
1answer
143 views

Finding the nth element of generalized Fibonacci sequences

I solved the Fibonacci Golf problem on checkio.org: The Fibonacci numbers or Fibonacci sequence are the numbers in the following integer sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21... This is not ...
2
votes
1answer
50 views

Project Euler Problem 52: Permuted multiples

This is my solution to Project Euler Problem 52 - Permuted Multiples. In the problem I'm searching for the smallest value of x such that x, 2x, 3x, 4x, 5x, and 6x use the same digits. ...
2
votes
1answer
30 views

Project Euler #11 in Ruby and some Iterations

Question: Given a 20x20 Grid of integers, find the greatest product of four adjacent numbers. (up, down, diagonal, reverse diagonal). ...
0
votes
0answers
28 views

Project Euler 78: Counting Partitions

I wrote the following solution to the coin partition problem. I use Euler's recurrence relation for the partition of n and that modular addition is associative; (a + b) % n = (a % n) + (b % n) % n. ...
3
votes
1answer
53 views

Project Euler #10 in Ruby. Three ways to sum primes below 2 million

Question: Add all prime numbers smaller than 2,000,000. The first method is done by deriving own is_prime? method: ...
4
votes
1answer
115 views

Project Euler #8 in Ruby

Question: For a 1000-digit number, find the 13 adjacent digits which gives out the largest product. My code goes like this: ...
4
votes
1answer
27 views

Project Euler #6 in Ruby

Question: Difference between the Sum of squares from 1 to 100 and the square of sums of 1 to 100. Answer in Ruby: ...
2
votes
2answers
28 views

Project Euler #5 in Ruby with Prime class

Question: Smallest positive number that is evenly divisible by all of the numbers from 1 to 20? I tackle the problem with reference to how I solved #3, which is using the ...
5
votes
1answer
62 views

Hacker Rank: Extracting digits from a given number and check for divisibility

The problem in question is a coding challenge from Hackerrank: Problem Statement You are given an integer N. Find the digits in this number that exactly divide N (division that leaves 0 as ...
3
votes
1answer
65 views

Pitting two Blackjack bots against each other

I'm taking part in this Daily Challenge on http://www.reddit.com/r/dailyprogrammer/comments/29zut0/772014_challenge_170_easy_blackjack_checker/ Basically, you have to develop a program that runs two ...
6
votes
1answer
402 views

Cutting The Sticks

Problem Statement This is a challenge from HackerRank: You are given N sticks, where each stick has the length of a positive integer. A cut operation is performed on the sticks such that all of ...
3
votes
3answers
104 views

Java FizzString

I am testing what knowledge I have with the FizzBuzz tests in Java. This is the one I just completed: Given a string str, if the string starts with "f" return "Fizz". If the string ends with "b" ...
4
votes
1answer
51 views

Create ranges from an array of integers

Given an array of ints, return a string identifying the range of numbers Example Input arr - [0 1 2 7 21 22 1098 1099] Output - "0-2,7,21-22,1098-1099" . Is there any improvement possible in this ...
3
votes
3answers
73 views

Frog jumping algorithm

I took a test on Codility for coding the minimum number of frog jumps to reach from position x to position y: A small frog wants to get to the other side of the road. The frog is currently ...