Tagged Questions
Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.
2
votes
2answers
19 views
Time Limit Exceeded for build_max_heap
This problem is from HackerEarth:
The Monk learned about priority queues recently and asked his teacher for an interesting problem. So his teacher came up with a simple problem. He now has an ...
2
votes
0answers
17 views
Computing the in-degree of a tweet graph
This was my entry for a recent coding challenge for computing the in-degree of a tweet graph (the competition is over).
The requirement was to compute the in-degree of a graph made from unique hash ...
0
votes
0answers
31 views
Pizza delivery problem: finding the best spot to set up a pizza shop
I received the following problem in an interview and submitted this solution but did not make it to the next round even though this was a working solution. I'm wondering how I can improve my code.
...
2
votes
1answer
38 views
Project Euler #23 with Java8 Streams
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 + 2 + 4 + 7 + 14 = 28, which means ...
1
vote
2answers
60 views
Project Euler #44
I'm having trouble optimizing my code for the exercise in Project Euler #44
Pentagonal numbers are generated by the formula, \$P_n=\frac{n(3n−1)}{2}\$. The first ten pentagonal numbers are:
...
-2
votes
0answers
12 views
Project Euler #8 Largest product in a series [migrated]
I am working on Project Euler's problem #8 in which I am asked to "Find the thirteen adjacent digits in this 1000-digit number that have the greatest product. What is the value of this product?"
Here ...
1
vote
3answers
135 views
Project Euler #43
I'm having trouble optimizing the Project Euler problem #43 :
The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also ...
3
votes
2answers
101 views
Project Euler Problem #41
I recently finished the project Euler problem # 41 :
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit ...
2
votes
3answers
213 views
Project Euler #34 Digit factorials
I'm having trouble improving the performance of the solution to the Project Euler problem #34
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
Find the sum of all numbers which ...
4
votes
3answers
37 views
User ranking system
I have written my first code of object oriented Python. Prior to this I have spent a week on learning the concepts and understanding the technique. I would appreciate it somebody reviews this and give ...
-2
votes
1answer
139 views
On Finding Coin Jams
The problem can be found here and is essentially asking us to generate J many numbers containing N many digits, where these digits have to be either 0 or 1. The catch is that the these numbers that we ...
4
votes
2answers
40 views
Copy Constructor for a linked list with self-referential pointers
I came across a coding challenge that looked something like this (recreating from memory, sorry)
Suppose you have the following interface for a linked list. Implement an efficient and correct ...
4
votes
2answers
39 views
Number of ways to make change for an amount
Task
Write a program that, given the amount to make change for and a list of coins prints out how many different ways you can make change from the coins to STDOUT.
My approach
The number to make ...
4
votes
2answers
268 views
Find prime positioned prime number
This is a question from programming contest. This contest is already over.
Now, all the prime numbers are arranged sequentially in ascending order. i.e:- 2, 3, 5,7...and so on. Now, your task is to ...
3
votes
1answer
191 views
Generators in Javascript; Project Euler #2
I'm trying to learn javascript using project euler and I decided to try to force myself to learn about generators in javascript using problem number 2 which asks us to: ...
4
votes
2answers
84 views
Project Euler #23 Non-abundant sums
I'm having trouble optimizing the Project Euler problem number 23 :
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 ...
3
votes
2answers
92 views
Project Euler GUI for Problem #1 through #11
I've been working on the Project Euler problems, so I created a GUI and a Solver class for all the code I've been creating. I'd like to share it with you guys and to get general feedback on my coding ...
4
votes
2answers
148 views
+50
Project Euler #11 Largest product in a grid
Question
Link to the exercise : https://projecteuler.net/problem=11
I'm currently working on the Project Euler exercise's and I just finished the eleven exercise. It's working fast enough it takes ...
20
votes
7answers
5k views
Project Euler #7 10001st prime
I decided to start working on the Euler project exercises. I'm doing fine for now but the seventh problem is running quite slow and I can't think of anything to make it work faster. It takes around ...
2
votes
2answers
46 views
Determine whether input-output pairs represent something that could be a proper math function
The input is read in line by line from stdin.
Input Format
The first line contains an integer, T, denoting the number of test
cases. The subsequent lines describe T test cases, and ...
1
vote
3answers
58 views
Project Euler - Smallest multiple (Ruby)
My code is very slow to run, and I am trying to find a way to make it more efficient. I know there must be a better way than to write each modulo operation.
The goal of the script is to find the ...
9
votes
2answers
106 views
Finding all contiguous sublists such that each member appears an even number of times
The program needs to find all contiguous sublists of numbers where the number of occurrences of every member in the contiguous sublist is divisible by 2.
The first line of input is N (the number of ...
1
vote
1answer
172 views
Google Foobar challenge: Rabbit Test Subjects
The diabolical Professor Boolean has captured you and a group of your
hapless rabbit kin as test subjects for his terrible experiments!
You're not sure what his real plans are, but currently it ...
1
vote
1answer
83 views
UVA #10258 - Contest Scoreboard
The problem statement is here.
Problem Description
The task is to rank the contestants in the contest based on following criteria
Contestants are ranked first by the number of problems solved (the ...
3
votes
1answer
80 views
Matrix rotation
Continuing on my VB.NET quest, I came across this slightly more challenging problem.
You are given a 2D matrix, a, of dimension \$M\$x\$N\$ and a positive
integer \$R\$. You have to rotate the ...
3
votes
3answers
58 views
Hackerrank Insertion Sort Part 2
I have started learning Java recently and was looking into the challenges on sorting on Hackerrank.I solved the following problemHackerrank on Insertion Sort.
The challenge was :
In Insertion ...
4
votes
1answer
49 views
Project Euler #127 abc-hits
Problem (Rephrased from here):
The radical of \$n\$, \$rad(n)\$, is the product of distinct prime factors of \$n\$. For example, \$504 = 2^3 × 3^2 × 7\$, so \$rad(504) = 2 × 3 × 7 = 42\$.
...
5
votes
1answer
57 views
Equivalent passwords ACPC 2014
I am preparing for ACM-TCPC (Tunisia). So I started solving problems from past ACM-ACPC versions. But I got stuck in the Problem I from 2014.
The problem consists of finding the number of ...
4
votes
1answer
43 views
Segmented Sieve of Eratosthenes in Scala
I'm trying to solve PRIME1 in SPOJ with the following Scala snippet:
Peter wants to generate some prime numbers for his cryptosystem. Help
him! Your task is to generate all prime numbers between ...
2
votes
2answers
45 views
PE # 34 - “Digit Factorials” with no loops
I posted a similar question “Curious Numbers” (HackerRank PE 34) recently (but in a different language/platform altogether). I'm starting to learn JavaScript and decided to take the challenge again ...
9
votes
5answers
238 views
Pizza Hut math problem #1 in Haskell
I'm currently attempting to learn Haskell after a fair history of imperative programming. When I saw the Pizza Hut Pi Day math problems, I thought the first one would be a good candidate for my ...
3
votes
3answers
90 views
Chess board in JS
I've completed the small challenge in the eloquent JS book to create a chess board pattern:
Write a program that creates a string that represents an 8×8 grid,
using newline characters to ...
1
vote
2answers
75 views
Google Code Jam: Store Credit Java Solution
It would be great if I could get this code reviewed.
I would love tips on how I could improve my code.
Problem
You receive a credit C at a local store and would like to buy two items. You ...
4
votes
1answer
97 views
Lazy prime number generator
There are multiple Project Euler problems (e.g. 7, 10) that deal with prime numbers. I decided make a reusable solution that could be used for most of them.
I wrote a method to generate an infinite* ...
7
votes
1answer
58 views
CS50 pset-1 itsa Mario - make a half-pyramid using parameters from user input
I'm taking Harvard's introduction to computer science (CS50) course online, and I've written a program that satisfies a coding challenge but I don't understand what I did or how I can improve it. I'm ...
8
votes
1answer
77 views
“Curious Numbers” (HackerRank PE 34)
I was inspired by a certain recent question to try my hand at this challenge:
Project Euler #34: Digit factorials
\$19!\$ is a curious number, as \$1!+9!=1+362880=362881\$ is divisible
by ...
4
votes
1answer
133 views
Finding the longest path, avoiding obstacles in a 2D plane
The Scenario
You are given a matrix of size m x n (width x height) with m*n spots where there are a few obstacles. Spots with obstacles are marked as 1, and those without are marked as 0. You can ...
2
votes
1answer
91 views
Printing longest sequence of zeroes
I am doing a coding exercise in codility and I came across this question:
A binary gap within a positive integer N is any maximal sequence of
consecutive zeros that is surrounded by ones at both ...
6
votes
2answers
89 views
Prime multiplication table
I am new to Ruby (1 year as hobby project on weekends) and solved a code challenge and it was not as good as they wanted. I want to know how i could make it better and how to make the structure ...
2
votes
3answers
127 views
Reverse digits and add until a palindrome appears
The following code is a C solution to the following problem UVA 10018.
The Problem
The "reverse and add" method is simple: choose a number, reverse its
digits and add it to the original. If ...
4
votes
1answer
45 views
Project Euler - Largest Product In A Grid
My code solves Project Euler problem #011:
What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?
I looked over one ...
5
votes
1answer
96 views
How to lose plants and aggravate people
Courtesy of a few posts around here I've discovered HackerRank. Poisonous Plants is one of their challenges.
Of course, skip the following if you'd like to try it yourself.
Challenge:
There are ...
3
votes
2answers
74 views
Find two numbers that add up to a given total, from a formatted string
The full challenge from codeeval.com can be viewed here.
Input
Your program should accept as its first argument a filename. This file
will contain a comma separated list of sorted numbers ...
0
votes
0answers
44 views
Comparing two integers without logical, relational or bitwise operators - followup
Requirement:
Compare the input numbers (granted to be non-negative) without logical, relational or bitwise operators and no if/else statement or ...
4
votes
1answer
80 views
Comparing two integers without logical, relational or bitwise operators
I answered a question on SO today, however it did't receive any up-votes, so I want to know what's wrong with my code.
The requirement is to compare the input numbers(granted to be positive) without ...
3
votes
1answer
75 views
Redirecting arriving customers to the nearest empty queue
I have a task to make a checkout line controller. First it receives, as input, an amount of checkouts and commands. Then commands that are C for coming and L for leaving, and after those the number of ...
3
votes
2answers
55 views
“ACM ICPC Team” challenge on Hackerrank
ACM ICPC Team
You are given a list of \$N\$ people who are attending ACM-ICPC World
Finals. Each of them are either well versed in a topic or they are
not. Find out the maximum number of ...
4
votes
2answers
76 views
Computing the divisor sum in bulk without division, multiplication or factorisation (SPOJ DIVSUM)
SPOJ problem #0074 DIVSUM - Divisor Summation requires computing the sums of proper divisors in bulk (200000 test cases, time limit 3 seconds):
Given a natural number n (1 <= n <= 500000), ...
4
votes
2answers
87 views
Finding the indices of the two items whose price adds up to to a value
I've solved the Google Jam store credit problem. but there's some inefficiencies that I want to get rid of them to improve the algorithm and reduce the multiple iteration. What are other better ways ...
3
votes
0answers
80 views
ACM-ICPC HackerRank challenge in C++
I was doing a programming question in C++ at HackerRank. Given a set of up to 500 bitstrings, each up to 500 bits long, the task is to find the pair a and b such that the bitwise OR contains the most ...