Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.
2
votes
0answers
26 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
30 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
57 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
32 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
27 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
86 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
55 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
49 views
Swift HackerRank Balanced Brackets
I solved this stack problem in Swift. Looking for any feedback on my code:
...
0
votes
1answer
36 views
HackerRank's Project Euler #10: Summation of Prime
Task- to find sum of all primes not greater than N
Input format- first line contains T, the number of test cases and second line N
Constraints- 1<=N<=10^6
I used the Sieve of Erastothenes. ...
0
votes
1answer
24 views
Project Euler 29 logic [on hold]
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
32 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, ...
0
votes
0answers
19 views
Project Euler #29 [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 ...
2
votes
2answers
153 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
59 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
56 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
47 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" ...
1
vote
2answers
55 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
73 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
446 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
51 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
194 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
39 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 ...
2
votes
1answer
27 views
Google Codejam 2016 Round 3 Problem A
I'm learning Rust by completing a variety of coding challenges, such as the Google Codejam problem stated in the title. I completed a Python 3 implementation that I liked, which I then tried to port ...
5
votes
4answers
78 views
Ruby solution to Project Euler Problem #4: Largest palindrome product
I've solved the Project Euler Problem #4, but I'd like some tips as to how to make this more efficient. I am a beginner to Ruby, so please be nice about the stupid stuffs (but still tell me about it).
...
3
votes
2answers
49 views
Print element in a linked list in reverse
I solved this problem in C++ and was looking for feedback on my code. I'm not sure if storing the data in an array and looping through it in reverse and printing was the right approach since this ...
2
votes
1answer
52 views
Sum of all paths between all pairs of nodes in a tree
I'm trying to solve a competitive programming problem. It basically gives a undirected graph (tree-like: no multiple paths between two nodes...) and asks for the sum of all possible paths between any ...
1
vote
1answer
22 views
Encoding and decoding in Haskell — 99 Problems exercise 13, 14
I've been working on these solutions to the Haskell 99 questions, encoding and decoding series for a while now, so I figured I ought to present them to see how I screwed up the implementation.
...
5
votes
2answers
51 views
Finding longest common prefix
I have been trying to solve a modification of the Longest Common Prefix problem. It is defined below.
Defining substring
For a string P with characters P1, P2,…, Pq, let us denote by P[i, j]
...
1
vote
1answer
45 views
Hackerrank Sparse Arrays in Swift
I solved this problem and was looking for feedback on my code. More efficient, cleaner, more verbose variable names, anything helps.
There are N strings. Each string's length is no more than 20 ...
3
votes
2answers
921 views
Morse Code Conversion
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 ...
1
vote
2answers
86 views
HackerRank Array left rotation using Swift
I solve this problem in Swift. Looking for feedback on my code or a better solution:
...
3
votes
2answers
64 views
Evaluating a completely parenthesized arithmetic expression
I tried to solve the following problem in a programming challenge, but the verdict was time limit exceeded.
Completely parenthesized expression
Write a program that reads a completely ...
1
vote
1answer
49 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 ...
2
votes
1answer
78 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
636 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 \...
7
votes
3answers
92 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 >...
4
votes
2answers
89 views
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\$?
...
10
votes
2answers
226 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
27 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
88 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
63 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
74 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
57 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 ...
1
vote
0answers
33 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
137 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
65 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
170 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 ...
5
votes
1answer
106 views
Hackerrank New Year Chaos
My code given below will produce the correct output but it tends to take way too much time with larger data thus timing out for some of the test cases. I've linked to the problem description here:
...
4
votes
1answer
39 views
Count the number of inversions using Binary Indexed Tree in an array
Original Problem: HackerRank
I am trying to count the number of inversions using Binary Indexed Tree in an array. I've tried to optimise my code as much as I can. However, I still got TLE for the ...