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

learn more… | top users | synonyms (2)

0
votes
0answers
45 views

Take two sets of randomly-sorted scores and find their common improvement percentage [on hold]

I was studying for an upcoming phone interview, and Googling programming terms which I needed to strengthen myself in. Well after I Googled "Dependency Injection", a banner appeared asking if I ...
3
votes
1answer
42 views

Evaluating a completely parenthesized arithmetic expression

I tried to solve the following problem in a programming challenge, but the veredict was time limit exceeded. Completely parenthesized expression Write a program that reads a completely ...
0
votes
0answers
16 views
1
vote
1answer
31 views

Swift Hackerrank Dynamic Array

I've solved this question. Wasn't sure if I was suppose to use a dictionary in this case, as the question was to use a dynamic array, but I didnt know how else to do it. Was wondering if I can get ...
1
vote
1answer
53 views

Swift Hackerrank 2D Array

I solved this question in Swift, but was wondering if there is a better way or if my code can be improved: Given a 6x6 2D Array: ...
4
votes
4answers
623 views

Find Watson's integer

Problem Statement: Watson gives Sherlock an array \$A_1\$, \$A_2\$ ... \$A_N\$. He asks him to find an integer \$M\$ between \$P\$ and \$Q\$ (both inclusive), such that, \$\min \{|A_i-M|, 1 \le i \...
0
votes
0answers
22 views

Hackerrank - Quicksort 2 in Swift [on hold]

I'm stuck on this problem. The whole code got ugly quickly, and the solution below did not work. Here is how I tried to solve quick sort: In the previous challenge, you wrote a partition method to ...
7
votes
3answers
85 views

How to decrease memory usage in codeeval Road Trip challenge

I'm solving easy CodeEval challenges in Python 2.7. Usually my solutions use around 256 bytes of memory according to CodeEval. With Road Trip however while time used is still low (30-40ms), memory is >...
3
votes
2answers
78 views
+50

Clojure performance for solving Project Euler 72 (counting proper reduced fractions)

This is a solution of Project Euler 72 in Java. How may proper reduced fractions \$\dfrac{n}{d}\$ are there, where \$n < d \le 10^6\$? ...
9
votes
2answers
203 views

Converting Morse Code

Challenge Write a program which reads a file containing Morse Code and outputs the conversion. Specifications The first argument is a path to a file. The file contains multiple lines. Each line ...
6
votes
1answer
26 views

Counting single degree vertex removal rounds (from a graph)

Problem: In this problem I had to remove all vertices with degree one from a given graph in rounds and count how many rounds are required to remove all possible vertices with degree 1. e.g. ...
8
votes
1answer
81 views

I CAN HAS EULR 14, PLZ?

A few days ago I found myself learning lolcode. It turns out it's (almost) a real language and capable of handling (pseudo-)serious problems. So, let's try some (pseudo-)serious code this time. ...
3
votes
0answers
61 views

Determining position of point W.R.T to given line equation

Problem from hackerrank:: Problem Statement: There are N lines. Each line has an index between 1 and N. The slope of ...
3
votes
2answers
64 views

Finding the index of the character whose removal will make a palindrome

Before I get into describing by problem I'd like to point out I found this question under c++ tag. But the solution of that question is already implemented in my ...
-1
votes
1answer
53 views

A Rule of Divisibility by 13

A Rule of Divisibility by 13 When you divide the successive powers of 10 by 13 you get the following remainders of the integer divisions: 1, 10, 9, 12, 3, 4. Then the whole pattern ...
-4
votes
0answers
20 views

Python indentation issues [closed]

I am an absolute newbie to Python and humbly apologize if this is too trivial an issue. I have developed the below code to generate Fibonacci numbers by reading input from a file :- ...
1
vote
0answers
30 views

Greedy solution to minimize the max-min spread

I wrote this solution to contest challenge and I am new to D and was hoping for some tips to make it faster or more Dish. The challenge is to select K integers from a list of N integers (2 ≤ N ≤ 105, ...
2
votes
1answer
105 views

Project Euler #5 - Smallest multiple using Factor Table

This is a problem from Project Euler and on Hackerrank (here)- 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the ...
2
votes
2answers
63 views

SPOJ ADDREV challenge - Adding reversed numbers

I'm a beginner Python (2.7) programmer, and I've just started solving basic problems on SPOJ. I correctly solved the ADDREV problem (http://www.spoj.com/problems/ADDREV/), however my code takes 0.06s ...
3
votes
1answer
165 views

“Parking” challenge solution

This is the problem statement. I have submitted successfully a \$O(n^2)\$ solution and I would like to know if there is a way to improve the running time to, maybe, \$O(n \log n)\$. Having dropped ...
1
vote
2answers
76 views

Project Euler #7: What is the 10,001st prime number?

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? How can I make this more efficient and cleaner? ...
4
votes
2answers
129 views

Pairwise programming challenge - Free code camp

Challenge: Given an array arr, find element pairs whose sum equal the second argument arg and return the sum of their indices. If multiple pairs, that have the ...
5
votes
2answers
630 views

Project Euler #5

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 ...
5
votes
6answers
734 views

Project Euler #4: Largest palindrome product

How can I make my code for Project Euler #4 more efficient and cleaner? Project Euler #4: Largest palindrome product: A palindromic number reads the same both ways. The largest palindrome made ...
3
votes
1answer
26 views

TLE on SPOJ for Prime Generator (PRIME1)

The objective is to find all primes between two given numbers. It is specified that the two numbers are \$\le\$ 1 billion and the difference between the two numbers is ~100,000. We are to repeat the ...
1
vote
2answers
146 views

HackerRank, Sherlock and Array

Here is the code I have written for a HackerRank challenge which takes multiple arrays, and attempts to determine if there exists an element in an array such that the sum of the elements on its left ...
2
votes
0answers
70 views

CodeEval - Lucky Tickets challenge

This a solution to the CodeEval's challenge "Lucky Tickets". After a failed attempt with brute-force calculations (no surprise here), I have tried to implement an algorithm that I found on ...
2
votes
2answers
71 views

SPOJ “It's a murder!” challenge

I wrote a solution for SPOJ "It's a murder!". I'm exceeding the time limit even after n log(n) solution and fast I/O. Given a list of numbers, I need to calculate the sum of the sum of the previously ...
3
votes
4answers
121 views

Remove adjacent duplicate characters

Introduction This problem is essentially equivalent to this HackerRank problem. The task is to remove all duplicate characters that are adjacent to each other in a given ...
5
votes
4answers
542 views

Project Euler 3: Largest prime factor

How can I improve my code, make it more efficient, and are there any tips you have? Project Euler 3: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the ...
8
votes
2answers
148 views

HackerRank Sherlock and Squares: count perfect squares in an interval

I've exceeded the time limit on Sherlock and Squares on hackerrank.com. Problem Given the number of test cases and a range (inclusive), find the number of numbers within that range that are perfect ...
5
votes
3answers
113 views

Snakes on a prime

The challenge is to find and print the largest palindrome prime under 1000. ...
23
votes
4answers
973 views

Generalized Project Euler 1: A sledgehammer to crack a nut

The problem Project Euler 1 is one of the most asked questions on site. However I wanted to solve the more general problem of division. Multiples of a list If we list all the natural numbers ...
6
votes
1answer
111 views

C the sum of primes

The challenge is to calculate the sum of the first 1000 primes. The code applies a sieve thanks to past answer, here, and works but I wonder about the flexibility of this solution. ...
7
votes
3answers
657 views

Mars rover movement and position

I have written a solution of a Mars Rover problem in C++ using OOP, but I am not fully satisfied with the design. What changes can I make to improve the design? Problem description is: A rover’s ...
5
votes
6answers
182 views

Counting pairs of relatively prime numbers

Problem from Hacker Earth: Inverted GCD: Given an array a of \$N\$ numbers , you have to find the number of pair of indices \$i\$ and \$j\$ that satisfy the following relation: \$i &...
8
votes
4answers
181 views

Project Euler 4: Largest palindrome product

This solves Project Euler 4: Largest palindrome product using C# (specifically, using LINQPad). Any and all suggestions for improvements to either the C# code or the math/algorithm are very welcome. ...
2
votes
0answers
30 views

SPOJ GENERAL: sorting by swaps of distance k

I have been trying to solve this simple problem on SPOJ for quite some time now, but I keep on getting TLE (Time limit exceeded) for some reason. Since the problem is in Portuguese, a brief ...
3
votes
3answers
60 views

HackerRank “Nested Lists” Code

I completed the "Nested Lists" challenge on HackerRank, and would love any feedback on my code. My program is fed text with the number of students in a classroom, the name of a student, and their ...
10
votes
5answers
848 views

Largest Prime Factor (PE3) using OOP

I want to learn some C# syntax/paradigms (I'm more used to Java), and have been wanting to get a bit better at math as well, so I solved ProjectEuler3: Largest prime factor with the following small ...
6
votes
1answer
66 views

Calculating protein mass

This question is part of a series solving the Rosalind challenges. For the previous question in this series, see A sequence of mistakes. The repository with all my up-to-date solutions so far can be ...
6
votes
1answer
60 views

Scrabble tile-counting challenge

While reviewing this Scrabble Tile Counter, I decided to give it a try myself. Here is the challenge, from Reddit's /r/dailyprogrammer: Description For this challenge we will be using the ...
1
vote
1answer
47 views

Hamming distance in Scala

Problem Write a program that can calculate the Hamming difference between two DNA strands. GAGCCTACTAACGGGAT CATCGTAATGACGGCCT ^ ^ ^ ^ ^ ^^ Code ...
2
votes
1answer
98 views

Reading Input from file for sorting and rewriting

I am writing a program that reads a DAT file with names. The names are stored in an ArrayList of Type Name, the Name object can hold the first, middle and last name. Once the names are stored in the ...
5
votes
2answers
65 views

Scrabble Tile Counter

Introduction Inspired by this r/dailyprogrammer problem, I've written a Scrabble tile counter. Given a Collection of Scrabble tiles known to be in play, it can ...
3
votes
3answers
154 views

Sorting and eliminating duplicates

From Hacker Earth: Problem Statement: Chotu's father is the owner of a Vada Pav shop. One Sunday, his father takes him to the shop. Father tells him that at the end of the day, Chotu has to ...
0
votes
0answers
34 views

Identifying Types of Triangle in Scala

Below is my solution to this exercise. Write a program that can tell you if a triangle is equilateral, isosceles, or scalene. The program should raise an error if the triangle cannot exist. ...
3
votes
1answer
79 views

Anagram in Scala

Code ...
0
votes
1answer
35 views

Calculating and printing a credit card balance

I am working on a problem that simply calculates and prints the credit card balance. I hope this code can be improved/optimized a lot. I am from a Java background. If it was Java code, I would have ...
3
votes
1answer
89 views

HackerRank “Save Humanity”

The "Save Humanity" problem on Hackerrank asks us to: ... find all substrings in the patient DNA that either exactly matches the virus DNA, or has at most one mismatch. For example: ...