Questions tagged [programming-challenge]

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

Filter by
Sorted by
Tagged with
11
votes
3answers
459 views

Print sums of all subsets

Print sums of all subsets of a given set Problem summary : Print all subset sums of a given set of integers My approach is to store previous results and use them to calculate new (similar idea as ...
11
votes
3answers
2k views

Pigeon and grain problem: find time until all the grain is eaten

Problem: There are \$n\$ pigeons and \$m\$ grains. Pigeon \$i\$ eats a single grain every \$x_i\$ seconds. Find the time until all the grain is eaten. Input: A line with the integer \$...
11
votes
4answers
2k views

“Restaurant” HackerRank challenge in C

I don't write C all that often, so things to look for would be memory leaks and such. I also recognize that I'm not validating the user input as well as I could - I could use some feedback on how I ...
11
votes
3answers
1k views

Optimizing “Herd Sums” problem using dynamic programming

I'm trying to solve a practice problem and all is well except for the last 2 inputs my solution is too slow. Just one loop is slowing it down I think. Herd Sums Execution Time Limit: 2 seconds ...
11
votes
1answer
2k views

Raindrops in Python

There's this simple coding challenge that feels like a twist on FizzBuzz. Your task is to convert a number to a string, the contents of which depends on the number's factors. If the number has 3 ...
11
votes
2answers
4k views

Lovely Lucky LAMBs

I am trying to solve this question from google's foobar. However, my code exceeds the time limit, even though when I tested it I got correct answers. How can I make my code more efficient? Lovely ...
11
votes
3answers
4k views

Students with second lowest grade

I solved the Nested List Python challenge on HackerRank.com passing all test cases. Although this problem can likely be solved with a short script with clever one-liners, my approach was instead to ...
11
votes
3answers
1k views

C itoa implementation

As an exercise, I limited my self to the man pages. I didn't look for a previous existing implementation because I wanted to see how well I could do on my own. I also tried to handle as many cases as ...
11
votes
2answers
11k 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: ...
11
votes
2answers
730 views

Breadth First Search to find connected primes

I've been working through the British Informatic Olympiad's 2016 Paper, and I've been struggling with some of the larger cases for question 3, specifically the larger cases on the mark scheme (the 3 ...
11
votes
3answers
4k views

Bathroom stalls in C (Google Code Jam 2017)

https://code.google.com/codejam/contest/3264486/dashboard#s=p2 Problem A certain bathroom has N + 2 stalls in a single row; the stalls on the left and right ends are permanently occupied ...
11
votes
3answers
5k views

Rounding a number up to the nearest multiple of a power of 2

I'm doing some programming challenges over at CodeEval and came across a pretty straight forward simple one: Given numbers x and n, where n is a power of 2, ...
11
votes
4answers
4k views

Codility binary gap solution using regex

Below is the code I implemented to solve the binary gap problem: Find longest sequence of zeros, bounded by ones, in binary representation of an integer. However, it seems to be different from ...
11
votes
1answer
186 views

Series, Powers, and Benches

Project Euler problem 48 The series, \$1^1 + 2^2 + 3^3 + ... + 10^{10} = 10405071317\$. Find the last ten digits of the series, \$1^1 + 2^2 + 3^3 + ... + 1000^{1000}\$. I made two different ...
11
votes
1answer
1k views

Memory-Test for Soldiers

I am solving the following problem on code chef: \$N\$ Soldiers are lined up for a memory test. They are numbered from 0 to N-1 from left to right. In the test, there are \$M\$ rounds. In each ...
11
votes
1answer
277 views

CodeVita challenge: forming the latest valid datetime in a year using some given digits

After answering someone's Code Review question, I decided to tackle a sequel: Given an input consisting of 12 non-decreasing single digits separated by commas, form the latest valid date time in a ...
11
votes
2answers
143 views

What a crooked way to compute the next straight string (advent of code 11)

This year I have been participating in the Advent of Code series of challenges, and it just so happened that I'd be doing them in Javascript. Not my usual weapon of choice, but I do have some ...
11
votes
1answer
391 views

Help me make my Python code clearer

Here's my solution to Project Euler problem 40. ...
11
votes
1answer
163 views

Check consistency of statements, with fuzzy rhyme matching (Kattis “Mårten's Theorem” challenge)

I wrote a review for Check consistency of a list of statements, with fuzzy rhyme matching, which basically required me to try writing my own solution to fully understand the challenge. So, I thought ...
11
votes
1answer
917 views

Saving the Universe - Code Jam 2008 Qualification problem A

I'm trying to brush up on my Python, so I'm going through some simple problems. Big concerns are style, though any algorithmic problems I'm open to suggestions on. Basically you have an input file ...
11
votes
1answer
270 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: ...
11
votes
1answer
186 views

A Structured FizzBuzz

Warning Wall of text, little bit of code. This question is about as much as introducing the language as it is about whether or not I still know how to write the language. Introduction Programmable ...
10
votes
4answers
3k views

Sum Square Difference, which way is more Pythonic?

I'm using python 3 and I am creating an algorithm to find the sum square difference for the first 100 (or 1 to x) natural numbers. This happens to be project euler problem 6 if anyone is wondering. I'...
10
votes
9answers
11k views

Project Euler #5 - Lowest Multiple of 1 through 20

I was trying to solve problem 5 of Project Euler, and this was I needed to do: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What ...
10
votes
7answers
19k views

Find if the string contains ALL the vowels

Problem: You are given a randoms string containing only lowercase letters and you need to find if the string contains ALL the vowels. Input: First line contains N , the size of the string. ...
10
votes
4answers
7k views

“Open and closed doors” riddle

Riddle Description: \$N\$ doors are closed. In the first pass, I open all of them. In the second pass, I toggle every second door. In the third pass, I toggle every third door. I continue this ...
10
votes
5answers
627 views

Camp challenges in one program

My counselor in a camp I went to over the summer gave me a code challenge. To take 6 challenges (listed below) and have all of them in one program, and have the user choose which one to use. Please ...
10
votes
5answers
987 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 ...
10
votes
4answers
677 views

PUT (Parallel Universe Time) generator

I don't like to post programming contest code in here, but I really like the question and want to share it with you all. It has been years since Superman started his enmity with the super-genius ...
10
votes
5answers
2k views

Project Euler #4: Finding the largest palindrome that is a product of two 3-digit numbers

Amateur c++ programmer here, working my way through the Project Euler problems (problem 4). I would love for someone to take a look at my ~40 lines of code and give suggestions on improving the ...
10
votes
2answers
2k views

Project Euler #7 10001st prime in C++

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 optimize this code? ...
10
votes
3answers
6k views

Find total number of phone numbers formed by the movement of Knight and Bishop on keypad

I recently gave a test on HackerRank, and submitted my answer for the following question. I passed all the test cases but company told me that the answer is not efficient, and they are not moving ...
10
votes
5answers
813 views

TDD for Euler Problem #4

I am in the process of learning Java and going through the Euler problems. For Problem 4 I decided to also implement a TDD approach with JUnit. My questions are: Is there a better TDD approach to ...
10
votes
4answers
2k views

Advent of Code 2017, Day 1: Sum of digits matching the next digit (circular list)

I haven't used C++ for quite a while and wanted to practice a bit, so I decided to start simple and work through the Advent of Code 2017. This is my solution to Part 1 of the Day 1 exercise "Inverse ...
10
votes
3answers
2k views

Simple Sudoku Solver in Python

This is my naive approach on implementing a Sudoku solver, which is okay for simple Sudokus like this: ...
10
votes
3answers
1k views

Solution to Project Euler Problem #37 in C++: Truncatable Primes

I was recently looking at some of my old Project Euler solutions, and saw that my implementation for Problem 37 could be improved drastically. The problem reads as follows: The number 3797 has an ...
10
votes
3answers
449 views

How can I make my solution for Chef and Digits run faster?

Problem Statement Given \$n\$ digits and \$m\$ indices \$x\$ from \$1. \ldots,n\$, calculate the difference \$b_y = a_x - a_y\$ for all indices \$y \; (y < x)\$. Then, calculate \$B1\$, the ...
10
votes
2answers
1k views

Perform a Caesar Cipher Shift on a given string

I'd like feedback on my solution to the outlined programming challenge (medium level). I've tried it fast in any way I know how to, but, what might be a more efficient and/or pythonic solution? [...
10
votes
2answers
642 views

Array duplicate removal for duplicates exceeding `N`-number

I recently encountered a front-end interview coding challenge question that required one to create a function which returned an array that excluded numbers that occurred more than ...
10
votes
4answers
626 views

Optimizing Project Euler Solution #12

Just to reiterate my prev. post, as I think it helps structure my weaknesses. Coding methodology: Is the algorithm I used feasible or mostly correct? If not, how do I correct it and why won't it ...
10
votes
5answers
607 views

Minimum perfect squares needed to sum up to a target

I'm trying to solve this problem Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n. I've come up with a solution that ...
10
votes
3answers
2k views

Imgur URL parser

Fairly new to Python, and I have been doing a few Edabit challenges, to better help with my problem-solving. I have just completed a some what semi-difficult challenge, and I was hoping for some feed ...
10
votes
2answers
875 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. ...
10
votes
3answers
18k views

Project Euler Question #2: Sum of even Fibonacci numbers under 4 million

The question is: 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, ...
10
votes
2answers
5k views

Fish Food Chain of complexity O(N)

I understand that if you don't know the trick, it's not easy create a solution with a complexity of \$O(N)\$. However, I would like to ask you how to solve this tricky question: You are given two ...
10
votes
3answers
2k views

Find the majority element, which appears more than half the time

The task: Given a list of elements, find the majority element, which appears more than half the time (> floor(len(lst) / 2.0)). You can assume that such element exists. For example, ...
10
votes
2answers
475 views

All the knight moves in all the right places

Challenge Find all possible moves for a knight on an empty chessboard. Specifications The first argument is a path to a file. The file contains multiple lines. Each line is a test case representing ...
10
votes
3answers
214 views

Project Euler Problem 10. Sum of all primes < 2mil

I'm new to coding so I can't create complex code yet. I do as much as I can with fors and ifs, since while I know a bit about ...
10
votes
2answers
568 views

Clean code attempt on codechef.com FCTRL

I have been reading Clean Code and decided to start working problems on Codechef.com attempting to apply some of what I have learned. Do I seem to be on the right track or am I way off? The ...
10
votes
2answers
10k views

Optimizing solution for Project Euler Problem #23 (non-abundant sums)

Project Euler Problem 23 asks: A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 ...

1 2 3
4
5
60