[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]

Help me design a whiteboard challenge for a job interview

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: 12
Thread images: 2

File: 1477197875551.jpg (1004KB, 2560x1600px) Image search: [Google]
1477197875551.jpg
1004KB, 2560x1600px
Since lately you've been on a anti-whiteboard questions tangent, here's your chance to make it right.

I will probably have to do a series of interviews and I want to test candidates for minimum knowledge of computer stuff. I don't care that you know Dijkstra's algorithm by heart because a) it has been implemented better than you could ever do it and b) you can always google it and find answers by people who teach this stuff for a living. Here's what I have in mind:

>cs challenge
Either fizzbuzz under n or sum of all primes under n. They're very simple problems that you should be able to solve in 20 minutes. I won't give a shit about details (oh, you forgot to start this iterator at 1 to avoid division-by-0, we'll be in touch), but I do care that for example you break/return as soon as you find that one number isn't prime. But honestly, if the overall idea makes sense, you made it.

>shell challenge
Find all files that start with a date in the 2017_04_18 format and end in .json, or given a bunch of text files, find all that contain a certain e-mail address. This is the sort of thing you'll have to do, companies usually have poor organization skills and it's important that you don't scour 20.000 folders by hand looking for something.

I'll also be posting solutions to simple whiteboard questions.
>>
File: 1492117107496.jpg (117KB, 728x546px) Image search: [Google]
1492117107496.jpg
117KB, 728x546px
*unsheaths whiteboard*
*teleports behind you*
psssh...nothin personnel...interviewee...
>>
Fizzbuzz, braindead-easy version:
#include <stdio.h>
#define MAX 100

int main(void) {
int i;
for (i=0; i<MAX; i++) {
if (i%15 == 0)
printf("fizzbuzz\n");
else if (i%3 == 0)
printf("fizz\n");
else if (i%5 == 0)
printf("buzz\n");
else
printf("%d\n", i);
}
}
>>
Sum of all primes, a bit harder. Only optimization is that I only check for division modulus of numbers up to half the number I'm considering and use a function to return 0 as soon as I find a number greater than 2 that divides it.
#include <stdio.h>
#define MAX 100
int isPrime(int n);

int main(void) {
int sum = 0;
int n;
for(n=2; n<MAX; n++) {
if(isPrime(n)) {
sum += n;
}
}
printf("%d\n", sum);
}

int isPrime(int n) {
int j, half;
half = (n%2==0.0 ? n/2 : (n+1)/2);
for(j=2; j<=half; j++) {
if(n%j == 0.0) {
return 0;
}
}
return 1;
}
>>
Check if a string contains 2 equal characters, one after the other. I did this one in Python because whoever tried would spend more time dealing with "how do I check for boundary conditions in an array" than actually solving the problem.
strings = [
"ababa",
"abba",
"a",
"bababbbb",
"ab b"
]

for string in strings:
for i in range(0, len(string)-1):
if string[i]==string[i+1]:
print(string)
break
>>
>>59955826
>fizzbuzz up to 2 million
>store fizzbuzz values
>sum all primes under each fizzbuzz
>randomize order of all the sums
>bubblesort.jpg
>put sums in binary search tree
>reverse the binary search tree
>do it in assembly
>>
>>59956259
Mad lad.
>reverse the binary search tree
Thanks, forgot about this.
>>
Bring ur own whiteboard and they would be very impressed and like wow this anon isnprepared webshould hire him.
>>
>draw a penis
this way you won't get any stupid sjw faggots working for you
>>
>>59955993
>n%2==0.0
>n%j == 0.0
Why not use the integer zero?

>(n%2==0.0 ? n/2 : (n+1)/2);
you don't need the distinction anyway. Just using n/2 would be good enough.
However, you can use the even better sqrt(n), once you realize that divisors come in pairs, which means sqrt(n) is the largest value you have to check.
You should also consider storing previously computed primes, because those are the only numbers you need to use in the isPrime test.

Those "optimizations" should be relatively obvious for any experienced programmer. Maybe they can't implement it in code immediately because time is short and they're nervous but they should at least have the idea and be able to explain it.
>>
>>59957152
>Why not use the integer zero?
True.
>you don't need the distinction anyway. Just using n/2 would be good enough.
But dividing an int by another int will floor the division, so for example in integer division 17/2=16/2=8, however in real arithmetic 8<17/2. Didn't know about sqrt(n), thanks.
>You should also consider storing previously computed primes, because those are the only numbers you need to use in the isPrime test.
How? I honestly can't see how this would be useful.
>>
>>59957346
>How? I honestly can't see how this would be useful.
The primes are the only numbers that really matter, because any number that's not prime will always have some smaller prime factors in it.
For example the number 6 is not a prime. And if a number is divisible by 6, then it's also divisible by its prime factors. (2 and 3). So you don't need to check for divisibility by 6. It's enough to check for divisibility of the prime factors of 6. This works for any number that's not prime.
So instead of going through all of the numbers from 2 to sqrt(n), you just go through the primes from 2 to sqrt(n) and you won't miss anything.
It speeds up the code quite a bit, because you can just skip all multiples of all primes in the isPrime function.
// This loop will always return before going out of bounds
for(int i = 0; ; ++i) {
// get the next prime
int prime = prime_array[i];
// are we done?
if(prime * prime > n) // or alternatively if(prime > sqrt(n))
return true;
// is number divisible by prime?
if(n % prime == 0)
return false;
}

And if you find a prime, you just add it to the array.
// ...
if(isPrime(n)) {
prime_array.push_back(n);
sum +=n;
}
// ...
Thread posts: 12
Thread images: 2


[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.