Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.
0
votes
0answers
10 views
Project Euler #4 - finding the largest palindrome from the product of two n-digit numbers
The code works well enough until trying to find the largest palindrome of two eight digit numbers. I found a similar question in C++, but there are some differences:
The main function takes two ...
0
votes
1answer
15 views
DailyProgrammer 280 Easy: Counting on Fingers
We are trying to count to 100 on two hands!
Input is given like so: LP LR LM LI LT RT RI RM RR RP (i.e. 0111011100)
Where:
...
-1
votes
0answers
16 views
Eulers Problem #3 Java Output Error [on hold]
I am currently attempting problem 3 of Euler's Problems and I have run into the problem where when the below code is compiled, all I get is "1" as output even though the for loop makes it run over ...
1
vote
2answers
48 views
FCFS with character invalid [on hold]
Any suggestion to improve this, they ask me to input characters that should be an invalid input and ask you again to input the number of process without crashing the program.
...
8
votes
5answers
139 views
Counting pairs of integers whose sum is less than a given threshold
Recently I was going through this codechef problem while practicing for the upcoming zoc.
The problem asks to calculate number of combinations of the given numbers where the sum is less than another ...
1
vote
1answer
32 views
LeetCode Counting Bits in Swift
I solve this problem in Swift. I am looking for a code review, thanks!
Given a non negative integer number num. For every numbers i in the
range 0 ≤ i ≤ num calculate the number of 1's in their ...
0
votes
0answers
21 views
Idiomatic string from/to integer conversions in Julia (Project Euler #33)
I am starting to learn Julia. For getting fluent in the syntax, I am solving some of the easier Project Euler challenges. Problem 33 is about so-called curious fractions, which keep their value after ...
0
votes
0answers
29 views
Project Euler #12 : Highly divisible triangle number in C++ [closed]
A newbie here. Can anyone help me with the mistakes in my code ?
First Triangle Number having more than N divisors.
...
0
votes
0answers
43 views
Stack which finds the minimum element
Write a program to implement stack which implements min a method
which gives the minimum element below the top element in the stack.
...
11
votes
3answers
1k 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 \$...
4
votes
4answers
65 views
Slow anagrams detection
This is my code for this question on hackerrank.
The idea is to find the amount of substrings of a given word that are anagrams of each other.
The code works fine, but it times out with longer ...
0
votes
1answer
37 views
8
votes
1answer
62 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 ...
2
votes
1answer
57 views
Generating numbers that are a product of consecutive primes
I have implemented a correct but horribly coded solution to Project Euler Problem 293.
An even positive integer N will be called admissible, if it is a power
of 2 or its distinct prime factors ...
0
votes
1answer
71 views
2D array challenge
I'm doing a hackerrank challenge to get ready for interviews and was wondering if someone could provide feedback on my code (style, naming convention, etc.). This challenge involves 2D arrays and is ...
6
votes
1answer
29 views
PE4: Largest Palindrome Product (Clojure)
I solved Project Euler 4 using Clojure Lisp.
A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the ...
1
vote
1answer
46 views
Project Euler 12 (triangle numbers), solved using functools.reduce() and looping
I have solved problem 12 on Project Euler website, which reads:
The sequence of triangle numbers is generated by adding the natural
numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 ...
0
votes
1answer
66 views
Project Euler #8 in C++: greatest product of k consecutive digits
This a problem from Hackerrank.com and Project Euler #8. The problem statement is as below. Is there a specific algorithm to solve such problems? Can my code be made more efficient?
Find the ...
2
votes
1answer
51 views
Order Statistics Tree on top of Treap
I built an Order Statistics tree on top of a Treap in order to solve this HackerRank problem. It works (passed all test cases). Any comments whatsoever would be greatly appreciated.
...
2
votes
3answers
35 views
CodeAbbey #21 Array Counters
I'm trying to learn some Haskell by working my way through the CodeAbbey problems. I really struggled to find a nice functional (but still efficient) way to solve problem #21: Array Counters.
The ...
2
votes
3answers
146 views
Programming challenge “Greatest Odd Divisor”
I am trying to solve a programming problem on a coding platform. When I submit the code on the coding platform, it throws a "Time Limit Exceeded" error. Can someone check my solution and help optimize ...
2
votes
2answers
82 views
Count consecutive ones in a binary list
There is a list consisting of zeroes and ones. I want to find out the length of the longest streak of ones. Is there a better solution?
...
1
vote
1answer
84 views
Program to calculate a student's test average
I made a very simple program where you input a students grades (edit the code with the set method?) and the program will output the average. Each test has a different weight associated with it.
The ...
5
votes
2answers
69 views
Project Euler #54 in Java: Comparing poker hands of two players
I was bored the other day and decided to have a crack at Project Euler Problem 54 for some fun. Given a file containing one thousand poker hands dealt to two players, the task is to count the number ...
3
votes
1answer
45 views
Code to merge sorted linked lists in java
Since I am using Hackerrank codepair, I have to resort to inner classes.
Please review the code and let me know if this can be improved.
...
2
votes
1answer
52 views
Hand crafted longest common sub sequence
I know that the below solution is not the best one and I am in the way to learn that stuff till then I have applied the brute force to see how far I can go with my intuition.
...
1
vote
2answers
56 views
Comparing adjacent time stamps
I have this code which compares two adjacent time stamps. If they are less than 15 min apart, it adds a new time stamp (row) in between with the new time stamp equal to the previous time + 15 min and ...
5
votes
2answers
103 views
Predict the best day to buy and sell the shares
I was trying out my hand at solving problems and came across this HackerRank problem. I have written a solution which passes for a few test cases but times out for most others (time limit - 3 seconds)....
4
votes
2answers
79 views
Big Nerd Ranch Bronze Challenge: Disallow Alphabetic Characters
I just completed BNR's bronze challenge for disallowing alphabetic characters, and would love some feedback on what I did right and wrong, and how I can improve my code for reusability and ...
2
votes
0answers
66 views
Hackerrank Simple Text Editor in Swift
I solve this problem in Swift. However, some cases I got terminated due to timeout because the solution isn't efficient enough. I did check the solutions and they are correct. Any tips on making it ...
4
votes
2answers
41 views
Finding an equilibrium index in an int array
Here is a programming challenge from codility
A zero-indexed array A consisting of N integers is given. An
equilibrium index of this array is any integer P such that 0 ≤ P < N
and the sum ...
6
votes
2answers
79 views
Codility binary gap solution using regex
This is how I solved 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 the answers out there. Is ...
7
votes
1answer
36 views
Kattis “Hitting the Targets” utilizing a polymorphic relashionship
In order to learn C++ I have written a solution to this Kattis "Hitting the Targets" problem
Basically the program is to accept some shapes (circles and rectangles) on std in and a set of points and ...
2
votes
0answers
35 views
Roman number converter in Kotlin
I'm learning kotlin and java. As a code-kata I wrote the roman to decimal converter. I'd be very grateful for code review.
I was trying to keep things simple and funcional. I'd especially appreciate ...
2
votes
2answers
111 views
HackerRank: Equal Stacks
This is my solution to the Equal Stacks problem on HackerRank. I thinks it's really messy and slow. could you give me some thoughts about how to optimize given code and algorithm(i'm pretty sure ...
4
votes
3answers
61 views
Time Limit Exceeded for ETF - Euler Totient Function at Spoj
In number theory, the totient φ of a positive integer n is defined to be the number of positive integers less than or equal to n that are coprime to n.
Given an integer n (1 ≤ n ≤ 106), compute the ...
3
votes
1answer
78 views
Swift HackerRank Balanced Brackets
I solved this stack problem in Swift. Looking for any feedback on my code:
...
0
votes
1answer
24 views
Project Euler 29 logic [closed]
I just finished Project Euler #29. And it worked successfully. But after comparing my answers to those from other folks, i realize my answer is wrong. Now it seemed to give me the correct example when ...
0
votes
0answers
50 views
Swift Hackerrank Maximum Element in a Stack
I solve this problem in Swift. I'm not sure if using an array was the right way to approach it since the problem was on stacks. Any feedback on my code is appreciated:
You have an empty sequence, ...
2
votes
2answers
171 views
Print numbers in a concentric square pattern
I am trying to solve a programming problem on a coding platform. When I execute it on my PC, it works perfectly, but when I submit the code on the coding platform, it throws a "Time Limit Exceeded" ...
2
votes
0answers
75 views
Solving the Mining algorithm from HackerRank
I was working on this problem for a few hours last night and finally came up with a brute-force solution. The task is to report the minimum work necessary (sum of weight × distance) to relocate gold ...
4
votes
1answer
70 views
“Similar Destinations” challenge
I am currently solving the Similar Destinations challenge on HackerRank and am in need of some assistance in the code optimization/performance department. The task is to take a list of up to 1000 ...
4
votes
1answer
65 views
Programming challenge “Friend Request in Social Network”
I am trying to solve a programming problem on a coding platform. When I execute it on my PC, it works perfectly, but when I submit the code on the coding platform, it throws a "Time Limit Exceeded" ...
0
votes
2answers
89 views
Google Foobar Challenge: Spy Snippets in Python [closed]
I am getting all the answers correct. But still the solution is not accepted as only 4/5 tests cases are passed.
I have not posted the whole problem statement but the problem is similar to this.
I ...
3
votes
1answer
81 views
Find the 10001st prime number (in C++)
I wrote this solution for project Euler #7, to find the 10001th prime number using sieve of eratosthenes. It's really slow though. Any suggestions to improve performance (without using more complex ...
10
votes
2answers
459 views
Project Euler #2: Even Fibonacci numbers
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, 89...\$
By ...
3
votes
2answers
55 views
Merge Two Sorted Linked Lists
I solved this problem in C++. I was having trouble though understanding what return headA; and return headB; returns after going back down the recursion tree. A code review is also appreciated!
...
5
votes
2answers
196 views
The Thirsty Crow
Problem Statement
There are N pots. Every pot has some water in it. They may be partially
filled. So there is a Overflow Number O associated with every pot which tell how many minimum stone pieces ...
0
votes
1answer
39 views
Binary to decimal converter in JavaScript
This exercise with a test suite is from here. I did not intend to use ES6 features, it's plain old JavaScript. That's why I seek advice more on the good practices, performance side, than modern syntax....
2
votes
2answers
46 views
Insert a Node at the Tail of a Linked List
I've solved this question, but have a small question. In the while loop we check if (temp->next != NULL), why wouldn't work if we check (temp != NULL). Isn't it the same, both checks will get us to ...