Programming challenges are off-site challenges meant to offer programmers educational experiences while testing their abilities.
3
votes
1answer
25 views
Segmented Sieve of Eratosthenes
I implemented this for the Prime Generator problem on SPOJ, but I am only getting 0.01s run-time, and would like to be able to match the run-times of the top submissions, which are all 0.00s.
What ...
2
votes
0answers
52 views
Hackerrank: Sherlock and anagram
Problem statement
Given a string \$S\$, find the number of "unordered anagrammatic pairs" of substrings.
Input Format
First line contains \$T\$, the number of testcases. Each testcase ...
7
votes
3answers
78 views
Leetcode 56: Merge Intervals
Problem statement
Given a collection of intervals, merge all overlapping intervals.
For example:
Given \$[1,3],[2,6],[8,10],[15,18]\$,
return \$[1,6],[8,10],[15,18]\$.
My ...
1
vote
1answer
48 views
Project Euler problem 2 in Haskell
I have just started Haskell, and I want to check if my code is following the spirit of the language.
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find ...
1
vote
1answer
38 views
Hackerrank Gemstones Solution
I'm looking for any possible improvements in terms of memory usage and speed, but really any advice is welcome.
Problem statement:
John has discovered various rocks. Each rock is composed of ...
4
votes
2answers
235 views
CodeWars: Gap in Primes
I wrote a javascript code for finding the first two consecutive prime numbers (that doesn't have divisors except one and itself) with a specific gap between them. It works well but take too much time ...
3
votes
2answers
73 views
4 sum challenge (part 2)
This is a continued discussion from (4 sum challenge) by return count only.
Problem
Given four lists A, B, C, D of integer values, compute how many tuples
(i, j, k, l) there are such that A[...
5
votes
2answers
116 views
Find K biggest numbers in the array
I was trying to implement method number 2, from this article.
Method 2 (Use temporary array) K largest elements from arr[0..n-1]
Store the first k elements in a temporary array temp[0..k-1]....
7
votes
0answers
48 views
Hackerrank - value of friendship (II)
Problem statement
You're researching friendships between groups \$n\$ of new college students where each student is distinctly numbered from \$1\$ to \$n\$. At the beginning of the semester, no ...
4
votes
1answer
51 views
Shortest Path For Google Foobar (Prepare The Bunnies Escape)
I have been working on Google Foobar since a few days ago. I am currently in the third level but is stuck in the second challenge of "Prepare the Bunnies' Escape."
I have checked this post but it did ...
4
votes
1answer
67 views
Assembly Line Scheduling challenge, solved using TDD
I am new to Test Driven Development and currently practicing it with some problem statement. Following is an Assembly Line Problem statement I solved using TDD approach in java. Please provide me some ...
3
votes
0answers
77 views
Selecting kids for a Christmas play with similar heights
I am doing this problem on SPOJ. The challenge is :
My kid's kindergarten class is putting up a Christmas play. (I hope he gets the lead role.) The kids are all excited, but the teacher has a ...
3
votes
0answers
27 views
Request for memory optimizations for solution to Google FooBar challenge, “ion_flux_relabeling,”
I just finished one of the Google FooBar Challenges.My Python is super rusty. I did the challenge in Haskell first and then attempted to covert the code. I am guessing that led to some bad Python ...
4
votes
0answers
84 views
4 sum challenge
Problem
Given four lists A, B, C, D of integer values, compute how many tuples
(i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.
To make problem a bit easier, all A, B, C,...
5
votes
1answer
60 views
Project Euler solution #2 using Swift 3
I just wanted some review and opinions. Any better implementations or suggestions would be great.
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting ...
5
votes
1answer
166 views
Hackerank - value of friendship
Problem statement
You're researching friendships between groups \$n\$ of new college students where each student is distinctly numbered from \$1\$ to \$n\$. At the beginning of the semester, no ...
3
votes
2answers
105 views
Create index-less array product
Source: careercup.com
You are given an array of integers(with all valid input) You have to
write a function which will produce another array, where the value in
each index of the array will be ...
3
votes
1answer
58 views
Assignement on reading from stdin in C
I am an experienced Python developer learning C. I solved this assignement:
Write a program that reads a word and some sentences from stdin. The word is separated by space from a sentences. The ...
1
vote
1answer
40 views
Codewars Challenge Kata
I was recently doing a challenge on Codewars and this is what challenge said:
There are no explanations. You have to create the code that gives the
following results:
...
3
votes
2answers
80 views
Finding Permutations of Numbers
I'm trying to solve this challenge, which consists of finding the next biggest number formed by the digits of the passed in number. If it is impossible to find a number larger than the passed in ...
0
votes
2answers
228 views
Capital Movement CodeChef challenge [closed]
PROBLEM
Suppose there are 'n' cities in a country out of which, one is the
capital. All of the cities are connected through 'n-1' roads so that
it's possible to travel between any two cities ...
2
votes
1answer
96 views
Merchant's Guide to the Galaxy
This is my version of Merchant's Guide to the Galaxy:
A merchant buys and sells items in the galaxy. Buying and selling over
the galaxy requires you to convert numbers and units. The numbers used
...
1
vote
2answers
50 views
Delta encoding a list of numbers
Given a list of numbers, e.g.:
25626 25757 24367 24267 16 100 2 7277
Output a delta encoding for the sequence. In a delta encoding, the first
element is ...
2
votes
1answer
48 views
Ashton and String Hackerrank
Online coding challenge Hacker Rank.
I tried to solve it using the naive appraoch first but its failing on some of the inputs and rest its getting timed out. How to get started in problem like these ...
3
votes
1answer
84 views
Find kth largest element in the union of two sorted array
Problem statement:
Find \$kth\$ largest element in the union of two sorted array.
My introduction of the algorithm
I spent a few hours to review two algorithms, Leetcode 4:Median of Two Sorted Arrays ...
2
votes
0answers
75 views
Hackerearth Simple Function - Follow-up
Problem statement
Let us first describe a SimpleFunction:
...
1
vote
1answer
91 views
Build String Hackerrank
Online challenge on Hacker Rank.
Please follow the description from the above link.
...
7
votes
3answers
248 views
Sort Characters By Frequency
I solved this problem.
Problem Statement
Given a string, sort it in decreasing order based on the frequency of
characters.
Example 1
Input: "tree"
Output: "eert"
...
3
votes
1answer
35 views
Trim to the nearest word under limit
Given a text and the length limit I need to trim the text to the word which is nearest to the limit.
...
5
votes
1answer
75 views
Custom Big Integer class for Project Euler in C#
I'm trying to teach myself some programming and, working through the Project Euler problems, I've come across some instances where I've needed numbers that are larger than will fit into an int or long ...
2
votes
1answer
170 views
BFS shortest path for Google Foobar challenge “Prepare the Bunnies' Escape”
This is the Google Foobar challenge "Prepare the Bunnies' Escape":
You have maps of parts of the space station, each starting at a prison
exit and ending at the door to an escape pod. The map is ...
4
votes
2answers
150 views
Find good numbers in a given range
This is the Good Numbers problem at Code Chef:
A number is called a square-free number if there does not exist a number greater than 1, whose square divides the number. For example, 8 is not a ...
1
vote
0answers
32 views
UVA: Y2K Accounting Bug
The Challenge
Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc. All what they remember is that MS Inc. posted ...
0
votes
0answers
31 views
2016 Advent of Code Day 3 Part 1 and Part 2
Continuing from earlier, here's a working solution to the Advent of Code Day 3.
With this one, a long list of triangle sides are provided, conveniently listed line by line. However, many of the ...
2
votes
0answers
29 views
2016 Advent of Code Day 2, Part 1 and Part 2
Continuing from yesterday, here's a simple solution in C to part 1 of Advent of Code Day 2.
I used a simple state machine to map from each keypad key to the next keypad key given the input.
...
-4
votes
0answers
42 views
for-loop to Query Expression Syntax[refactor the for-loop] [duplicate]
A quick description on the problem I solved on codewars.com but remember I just want a small part of my solution refactored (Just the for-loop)
This is similar to climbing the stairs but I am just ...
3
votes
1answer
60 views
UVa 11340 Newspaper challenge (sum of letter values in an article)
I am solving the UVA 11340 problem:
Problem Description
News agency pays money for articles according to some rules. Each
character has its own value (some characters may have value equals ...
1
vote
1answer
59 views
MaxCounters solution
I am doing this Codility problem
You are given N counters, initially set to 0, and you have two possible operations on them:
increase(X) − counter X is increased by 1,
max counter − all ...
5
votes
3answers
179 views
Project Euler #47: Distinct primes factors
I have solved Project Euler's problem number 47, which reads:
The first two consecutive numbers to have two distinct prime factors
are:
14 = 2 × 7
15 = 3 × 5
The first three ...
3
votes
3answers
99 views
Two strings to one containing distinct letters
I've been doing lately CodeWars and here's my working code for this challenge.
The challenge :
Take 2 strings s1 and s2 including only letters from a to z. Return a new sorted string, the longest ...
5
votes
1answer
160 views
Climbing the stairs
A quick description on the problem I solved on codewars.com but remember I just want a small part of my solution refactored (just the for-loop):
Description
...
1
vote
1answer
71 views
Closest Numbers
Online coding challenge Hacker Rank.
Given a list of unsorted integers, find the pair of elements that have the smallest absolute difference between them? If there are multiple pairs, find them all.
...
1
vote
2answers
259 views
Hackerrank: Connected Cells in a Grid
Problem statement
Consider a matrix with \$n\$ rows and \$m\$ columns, where each cell contains either a \$0\$ or a \$1\$ and any cell containing a is called a filled cell. Two cells are said to be ...
5
votes
1answer
190 views
22
votes
3answers
4k views
Decoding C program
I've built a C decoder program. The length of an encoded message will be given and the message itself in the following line. All the characters of the message will be in uppercase letters. The task is ...
4
votes
1answer
34 views
Advent of Code 2016: Day 1, Part 2
This is a continuation of Advent of Code 2016: Day 1, Part 1.
This time, instead of the distance at the end of the instruction string, the answer is the distance of the first location which is ...
1
vote
1answer
57 views
LeetCode: Add Two Numbers (in Kotlin)
(...as I still learning Kotlin) I found this "problem":
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain ...
11
votes
2answers
192 views
Cows with walkie-talkies (USACO Silver Prob. #3; December '16 )
The official problem description is here, which in my opinion is unclear and quite long. Below is my description. I recommend you still read the official description, it has details such as input and ...
3
votes
1answer
67 views
String puzzle - operations with numbers inside of strings
Puzzle description: input is dimensions (length, width, heigth) of various presents.
Example:
2x3x1
5x9x10
1x40x2
Part 1: determine the area of paper ...
3
votes
2answers
109 views
Sherlock and Anagrams
Given a string S, find the number of "unordered anagrammatic pairs"
of substrings.
Input Format
First line contains ...