Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.
2
votes
1answer
71 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
0answers
25 views
Retrieves largest, rightmost substring with maximum of two different characters [on hold]
This challenge is a famous interview question and I hope you're all familiar with it.
Given a string, our mission is to find the longest substring that contains, at most, two unique characters. If ...
2
votes
2answers
56 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
155 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
73 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
118 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
622 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
722 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
24 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
138 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
68 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
69 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
120 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
518 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
140 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
103 views
23
votes
4answers
955 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
100 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
649 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
176 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
171 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
51 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
843 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
65 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
59 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
44 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
96 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 ...
4
votes
2answers
62 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
153 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
30 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
72 views
0
votes
1answer
34 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
86 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: ...
7
votes
2answers
84 views
Sum of prime factors of binomial coefficients over 9000!\${}\$
The problem
I have lately been working Project Euler: 231:
The prime factorisation of binomial coefficients
The binomial coefficient \$ ^{10}C_3 = 120 \$.
\$ 120 = 2^3 × 3 × 5 = 2 × 2 ...
1
vote
1answer
28 views
HackerRank “Lists” code
I completed the following exercise on HackerRank. My program is fed a list of commands, such as:
...
4
votes
3answers
578 views
Project Euler 10: find the sum of all the primes below two million
This is question #10 from Project Euler:
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million.
I just started programming and read that a Sieve ...
5
votes
1answer
135 views
Printing fizzy lines
Challenge
Given a test case print out a FizzBuzz Series.
Specifications
The first argument is a path to a file.
Each line includes a test case.
Each test case is comprised of three spaced ...
3
votes
1answer
83 views
Minimum window substring
The minimum window substring problem from leetcode.com asks:
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity \$O(n)\$.
...
3
votes
3answers
98 views
Find All the Primes Between two Numbers
I wrote a solution to the Coding Challenge SPOJ Prime in C++ using the Sieve of Eratosthenes. How much Ever I tried I could not get over the Time Limit on SPOJ which is 6s for Primes upto 1000000000.
...
0
votes
1answer
76 views
Project Euler #50 Consecutive prime sum
I'm having trouble optimising the project euler #50 exercise, it runs for around 30-35 seconds, which is terrible performance.
The prime 41, can be written as the sum of six consecutive primes:
...
4
votes
3answers
54 views
Codewars “Find the Parity Outlier” code
I completed this Codewars exercise. Here are the instructions:
You are given an array (which will have a length of at least 3, but
could be very large) containing integers. The integers in the ...
3
votes
1answer
82 views
Project Euler #49 Prime permutations
Today I solved problem #49 from project euler .net which reads :
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the ...
6
votes
3answers
511 views
Create an array with the highest values from each array
I am working my way through FreeCodeCamp's Javascript challenges and Return Largest Numbers in Arrays took me a minute. In this one the goal was to create an array with the highest values from each ...
3
votes
1answer
43 views
Project Euler 23 - Non-Abundant Sums
I'm new to Python! Kindly suggest me improvements!
Problem statement :
A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum ...
9
votes
2answers
821 views
C the large print
This is the Longest lines challenge from CodeEval:
Challenge
Write a program which reads a file and outputs a specified number of lines, sorted on length in descending order.
...
1
vote
1answer
62 views
ChocolatesByNumbers- Find the number of N chocolates in a circle
Recently, i have been indulging in a lot of codility challenges to improve my coding performance. For each of this exercise, I always aim for simple solutions as opposed to complicated ones that ...
2
votes
2answers
71 views
Circular primes below 10^1025
The problem
Project Euler: 35 is stated in the following way
Circular primes
Problem 35
The number, 197, is called a circular prime because all rotations of
the digits: 197, 971, and ...
8
votes
1answer
116 views
Snakes and Letters
This is the "Clean up the words" challenge from CodeEval:
Challenge
Given a list of words mixed with extra symbols. Write a program that will clean up the words from extra numbers and symbols....
3
votes
1answer
60 views
Printing longest lines
Challenge
Write a program which reads a file and outputs a specified number of lines, sorted on length in descending order.
Specifications
The first argument is a path to a file.
The file ...