Write a quick sort algorithm on that whiteboard
To sort what?
How quick?
Okay
I am hired
>>59922026
>O(1) will do for now, that's quick I think *giggles*.
>>59922042
You even failed at that.
>>59922042
>ing
Welcome to the local no-hire list son
>>59922045
Bucket sort.
Done.
>>59922053
>>59922065
fugggg
qsort(values, 5, sizeof(int), cmpfunc);
Does she mean quicksort or any fast sorting algorithm
>>59921893
what in le h*ck is quicksort???
sudo rm rf
>>59921893
well i will use some pseudo code if thats fine but you should get the idea :)import alg.qsort
qsort([24,1,241,5])
>>59922221
fuck my get :(*
give it back to me you asshole >>59922222
def gasTheKikes(juddenList):
if len(juddenList)==0:
return juddenList
shlomoPivot=juddenList.pop()
return gasTheKikes(list(filter(lambda judden: judden<shlomoPivot , juddenList)))+[shlomoPivot]+gasTheKikes(list(filter(lambda judden: judden>=shlomoPivot , juddenList)))
>>59921893function quicksort(S):
choose x in S randomly
S1 = {}
S2 = {}
for el in M\{x}:
if el < x:
S1 = S1 U el
else:
S2 = S2 U el
return quicksort(S1) U {x} U quicksort(S2)
>>59922339
this looks nice, what language is that? looks like lua.
>>59922365
it's pseudocode
Write
:(){ :|: & };:
>What is this???
>Cum wit me and I'll show you.
>Ok
>>59922339
meant to writefor el in S\{x}
>>59921893function quicksort(arr) {
if(!arr[0]) return [];
var smalr = [];
var bigr = [];
var piv = arr[0];
for(i=1; i<arr.length; i++) {
if(arr[i] < piv) {
smalr.push(arr[i]);
} else {
bigr.push(arr[i]);
}
}
return quicksort(smalr).push(piv).concat(quicksort(bigr));
}
>>59921893
quickSort :: (Ord a) => [a] -> [a]
quickSort [] =[]
quickSort (x:xs) = quickSort(filter (<=x) xs) ++ [x] ++ quickSort( filter (>x) xs)
>>59922497
What language?
>>59922561
lisp
>>59921893
> *cooly flip the whiteboard 360°*
> *walk out of the room*
>>59922561
javascript
>>59922313
>shlomoPivot
lost
>>59922561
Haskell
I can't remember the solution to any sorting algorithsm off the top of my head. How bad is that?
>>59923168
Just kys now.
>>59923168
It means that you're out of practice. Do yourself a favour and implement some basic sorting algorithms just for practice and then put them somewhere handy so you can revisit them when you need them.
>>59922143
>Like a quicksort specifically or do you just want to me to quickly write any sort algorithm?
>"This interview is over, please leave."
>>59921893
Why not just use `sort`?
>>59922404
First time i showed this to a normie, he thought i was hackerman and that i broke his pc.
Take the array, put it in a random combination and check if it's sorted.
I don't care if will take years if you have a million entries this is why we have better hardware
>>59922143
She means quicksort, but you can always implement one of the optimised versions after you implemented the basic version.
import java.math.Random;
public class fug {
public static void main(String[] args) {
Random r = new Random();
System.out.println(r.nextInt());
}
}
>>59923464
Won't work for longer lists.
>>59923566
it is guaranteed to.
>>59924470
Your prng is unlikely to generate the sorted permutation ever.
>>59924562
>unlikely
As long as there is a chance. Cosmic rays may flip the right bits.
>>59924572
You can't guarantee that.
>>59924584
No, but I can guarantee you that a bogosort implementation (or sleep sort implementation) will get you further in the interview based on humour points (as long as you also do it correctly).
#import <qsort.h>
>>59923438
What is this really though?
>>59922339
>choose x in S randomly
How do you do this?
cat list.txt | sort
>>59924679
use a built-in random integer generator and input 0, length of S as the range
alternatively, always pick the element closest to |S| / 2.
>>59924562
>>59924584
you can guarantee that it will happen, just not before the universe's brownout
>>59925103
No you can't.
>>59921893
sure just let me google that real quick
>>59925275
With a large enough number of computers sorting their own copy of the same numbers, you can guarantee that at least one of them will sort it given infinite time.
>>59925298
Depends on how their prngs are seeded.
>>59925430
It's more likely the cosmic rays crash your program.
def part(A, lo, hi):
p = random.randint(lo,hi)
val = A[p]
A[p],A[hi] = A[hi],A[p]
i,j = lo,hi-1
while i < j:
if A[i] > val and A[j] < val:
A[i],A[j] = A[j],A[i]
if A[i] <= val:
i += 1
if A[j] >= val:
j -= 1
p = i
if A[i] < val:
p += 1
A[p],A[hi] = A[hi],A[p]
return p
def qs(A, lo=None, hi=None):
if lo is None:
lo = 0
if hi is None:
hi = len(A)-1
if lo < hi:
p = part(A, lo, hi)
qs(A, lo, p-1)
qs(A, p+1, hi)
>>59925449
Yes indeed, but with a large enough number of computers and long enough time, even though most of them will crash, some of them will complete the run with the correct result.
>>59925557
There's not enough cosmic rays if the list is length one million.
>>59925658
>There's not enough cosmic rays if the list is length one million.
There are more stars in the galaxy than there are atoms in the universe, so of course there is.
>>59924650
A simple Bash forkbomb. It's notable because of how pretty and elegant it is.
>>59925684
>There are more stars in the galaxy than there are atoms in the universe
Makes sense.
>>59925529
>>59923522
>>59922437
>>59922339
>>59922221
>>59922131
>on that whiteboard
>>59922042
she gives u this look
>>59921893
node notstolenfromstackexchangesortexample.js
Do I get the job? I am a great coder, I got the #kodewithkarlie scholarship.
>>59924572
>Cosmic rays
gb2mario speedrunning, memory has errors for plenty of reasons
#include <algorithm>
using namespace std;