Serving the Quantitative Finance Community

 
User avatar
bluetrin
Topic Author
Posts: 2
Joined: September 9th, 2005, 6:41 am

Codility challenges

September 15th, 2014, 8:10 am

Codility.com is doing challenges, I think they are a bit easy for you guys but maybe you will find this somehow interesting:https://codility.com/programmers/challenges/
 
User avatar
tags
Posts: 3603
Joined: February 21st, 2010, 12:58 pm

Codility challenges

September 15th, 2014, 10:43 am

Hello bluetrin, I posted yesterday on this, in another thread.QuoteOriginally posted by: tagomacodilityCongrats for your prize. What was the sulfur challenge about?
 
User avatar
bluetrin
Topic Author
Posts: 2
Joined: September 9th, 2005, 6:41 am

Codility challenges

September 15th, 2014, 11:09 am

QuoteOriginally posted by: tagomaHello bluetrin, I posted yesterday on this, in another thread.QuoteOriginally posted by: tagomacodilityCongrats for your prize. What was the sulfur challenge about?You can just click on their link and attempt the challenge as many times as you want. The Sulphur is fairly easy, they give you ropes which have a certain strentgh and a weight attached to it.Then they give you for this ordered list of ropes where you will attach them (for example either to a nail or to another rope), if a rope happen is supporting a heavier weights than its strength it will break.The problem is to find when the first break will happen.It is not that hard, have a go if you have some time. QuoteOriginally posted by: outrunTsk, the first example does a recursive Fibonacci in JavaScript that can cause stack overflows and has O(N) runtime!Anyone knows you can solve the recurrent relation with Binet's golden ratio equation. *quickly google Binet's golden ratio*
Last edited by bluetrin on September 14th, 2014, 10:00 pm, edited 1 time in total.
 
User avatar
tags
Posts: 3603
Joined: February 21st, 2010, 12:58 pm

Codility challenges

September 15th, 2014, 1:34 pm

Quote*quickly google Binet's golden ratio* Is typing 3.5 characters per second fast enough to return valuable google results?
Last edited by tags on September 14th, 2014, 10:00 pm, edited 1 time in total.
 
User avatar
agonz
Posts: 0
Joined: October 27th, 2014, 2:05 pm

Codility challenges

October 28th, 2014, 3:59 pm

Hey guys, was able to solve the challenge but only got the silver award, the detected complexity of my algorithm is O(NlogN) but it seems to have some scalability issues. Could you give me some hints on how to make it more efficient? (didn't quite understand how to apply the fibonacci to this particular problem).Thanks!
 
User avatar
agonz
Posts: 0
Joined: October 27th, 2014, 2:05 pm

Codility challenges

October 28th, 2014, 8:28 pm

In a room there are N ropes and N weights. Each rope is connected to exactly one weight (at just one end), and each rope has a particular durability − the maximum weight that it can suspend.There is also a hook, attached to the ceiling. The ropes can be attached to the hook by tying the end without the weight. The ropes can also be attached to other weights; that is, the ropes and weights can be attached to one another in a chain. A rope will break if the sum of weights connected to it, directly or indirectly, is greater than its durability.We know the order in which we want to attach N ropes. More precisely, we know the parameters of the rope (durability and weight) and the position of each attachment. Durabilities, weights and positions are given in three zero-indexed arrays A, B, C of lengths N. For each I (0 ≤ I < N):A is the durability of the I-th rope,B is the weight connected to the I-th rope,C (such that C < I) is the position to which we attach the I-th rope; if C equals −1 we attach to the hook, otherwise we attach to the weight connected to the C-th rope.The goal is to find the maximum number of ropes that can be attached in the specified order without breaking any of the ropes.Write a function:def solution(a, b, c)that, given three zero-indexed arrays A, B, C of N integers, returns the maximum number of ropes that can be attached in a given order.For example, given the following arrays: A[0] = 5 B[0] = 2 C[0] = -1 A[1] = 3 B[1] = 3 C[1] = 0 A[2] = 6 B[2] = 1 C[2] = -1 A[3] = 3 B[3] = 1 C[3] = 0 A[4] = 3 B[4] = 2 C[4] = 3the function should return 3, as if we attach a fourth rope then one rope will break, because the sum of weights is greater than its durability (2 + 3 + 1 = 6 and 6 > 5).Given the following arrays: A[0] = 4 B[0] = 2 C[0] = -1 A[1] = 3 B[1] = 2 C[1] = 0 A[2] = 1 B[2] = 1 C[2] = 1the function should return 2, as if we attach a third rope then one rope will break, because the sum of weights is greater than its durability (2 + 2 + 1 = 5 and 5 > 4).Assume that:N is an integer within the range [0..100,000];each element of array A is an integer within the range [1..1,000,000];each element of array B is an integer within the range [1..5,000];each element of array C is an integer such that −1 ≤ C < I, for each I (0 ≤ I < N).Complexity:expected worst-case time complexity is O(N*log(N));expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments).
 
User avatar
agonz
Posts: 0
Joined: October 27th, 2014, 2:05 pm

Codility challenges

October 29th, 2014, 5:39 pm

Thanks for your response! it is quite similar to my algorithm (see attached code). Anyways, I tried submitting yours and it also has the 'scalability' issues and didn't get the 100% score :s ... I cannot think of a better way of solving it
Last edited by agonz on October 28th, 2014, 11:00 pm, edited 1 time in total.
 
User avatar
agonz
Posts: 0
Joined: October 27th, 2014, 2:05 pm

Codility challenges

October 29th, 2014, 11:11 pm

It doesn't work either :s (had to do a small tweak to make it work since it has an issue with edge cases like no ropes passed in, etc), it is correct but has scalability issues. if you want to play around (and get detailed outputs) you can go here https://codility.com/programmers/custom ... ulphur2014 (you don't have to register, just enter your name and email to print it out in the certificate when you earn one)
Last edited by agonz on October 29th, 2014, 11:00 pm, edited 1 time in total.