[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Preparing for algorithm test

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 23
Thread images: 1

File: Untitled.png (108KB, 1365x668px) Image search: [Google]
Untitled.png
108KB, 1365x668px
Have 2 weeks to prepare for a coding test. I think the topic will be timed algorithms.

I've done back and front-end coding for websites for years, know basic types, and linux commands.

But I'm completely unconfident when it comes to complex algorithms. I can only sum primes because I memorized Eratasthenes sieve after reading 4chan memes.

What material should I look at or practise over the next two weeks to improve my chances of doing well on one of these tests?
>>
You wouldn't need to ask this at all if you had any semblance of a math education, eg. a CS degree.

This is what happens when self-taught retards think they gamed the system and think they're on the same intellectual level as educated applicants.
>>
>>59830343
fpbp
>>
What site is that in the pic?
>>
That assignment seems easy.
Just get it working, test the edge cases to verify it really does work, and then think about how it could work better.
>>
>>59830343
I have a 2 year college degree and I'm trying to use a website to get paid $20-$30 an hour to be a code monkey.

Not trying to take your precious spot at the big 4 just trying to learn enough about algorithms to pass a competency test.
>>
>>59830316
I did a codility test recently and didn't involve much more than manipulating arrays and most math involved was some triangle numbers.
You've got 3 hours to figure it out so don't worry too much and you can always use google.
>>
>>59830316
Wait, is this asking what the mode of the array is?
This is piss easy.
>>
>>59830469

No.
The question is this:
>If there exists some element A[i] such that the sum of every element from A[0] to A[i-1] equals the sum of every element from A[i+1] to A[n], return that i. Else, return -1.
Pathetically easy to hack something together that finds the solution even if it's slow and inefficient as fuck.
>>
>>59830523

My attempt after reading your description of test:

function checkEqual(A) {
for (i = 0; i < A.length; i++) {
var tempArray = A;
secondHalf = tempArray.splice(0, arr2.indexOf(i));
sum1 = 0;
sum2 = 0;
for(j=0; j < tempArray; j++) {
sum1 += tempArray[j];
}
for(j=0; j < secondHalf; j++) {
sum2 += secondHalf[j];
}
if(sum1==sum2) return true;
}
return false;
}

for(var i = 0; i < array.length; i++)
{
count = count + array[i];
}
>>
>>59830670
fuck I lost my indents ...
>>
>>59830670
you don't need to prove that you can do this, it's so easy it's almost banal.
>>
>>59830692
I found it difficult to even extract the problem from the text.

I imagine this is easier than the actual question I'll get. Maybe I'll try using that hacker rank site or something.
>>
>>59830670

That gets you mostly the right solution but you haven't accounted for overflows (use a long instead) or the special case of the empty array.

Also it runs in O(N^2) time which the site complains about.
>>
>>59830719
Do you now if it is possible to do at O(N) ?

I understand what this means but to be honest I really have to read over it again and again to actually understand that it is O(N^2).

I really want to improve on this.
>>
>>59830739
I guess any loop within a loop becomes O(N^2) (?)
>>
>>59830739

Here's my solution. It's almost right, but doesn't account for the empty array, but it runs in O(N) time.
class Solution {
public int solution(int[] A) {
long left = 0;
long right = 0;
// Initial right sum
for (int i = 1; i < A.length; i++)
{
right += A[i];
}
// Each time the next i is tested for equilibrium, increment left by the new left element and decrement right by the old right element
if (left == right)
return 0;
for (int i = 1; i < A.length; i++)
{
left += A[i-1];
right -= A[i];
if (left == right)
return i;
}

// Not found
return -1;
}
}


At the beginning, I test the index 0 to see if it's an equilibrium. I sum all the elements to the right of my supposed equilibrium.
If 0 doesn't work, I try 1 instead. I add the new element that is now to the left of my equilibrium (A[0]) to my left-sum, and then remove the old element that is no longer to the right of my equilibrium (A[1]) to my right-sum.
And then I just loop until all indices have been tested.
>>
>>59830399
Are you blind?
>>
OP, I took that test and it failed me because my answer didn't meet specific requirements that they didn't disclose before I submitted my answer.
Despite being correct, I got a 0 out of 100.
This is how they fail you: https://codility.com/demo/results/demoDGRKFM-52T/

They're not going to hire you OP, I suggest you look elsewhere.
>>
>>59830993

>for (i = j; i < N; i++)
>i = j;
no you fucking retard, you misunderstood the problem.
>>
>>59831026
Maybe they should have described their problem better.
This shit is basically unicru on steroids, just another way to throw your resume into the black hole.
>>
>>59831064

The problem is perfectly legible, you're just thick.
>>
>>59831087
>https://codility.com/demo/results/demoDGRKFM-52T/

>oh i'm sorry, another applicant scored an 83% on the codablity test, we're not going to move forward with your application at this time
Thread posts: 23
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.