Nice resume user, we're just gonna do a basic whiteboard coding exercise

>nice resume user, we're just gonna do a basic whiteboard coding exercise

>in your preferred language, find the median of two sorted arrays and please walk me through your thought process!


why is the tech industry so fucking garbage?

Other urls found in this thread:

discuss.leetcode.com/topic/4996/share-my-o-log-min-m-n-solution-with-explanation
twitter.com/SFWRedditVideos

why does this upset you
it sounds easy as fuck

shut the fuck up retard, I guarantee you couldn't find the optimal solution under 1 hour coding on a fucking whiteboard

the answer is here: discuss.leetcode.com/topic/4996/share-my-o-log-min-m-n-solution-with-explanation

and im certain 99% of Sup Forums would fail miserably.

If the value range is unsigned and small enough, I'd just make a lookup table of type struct { int n, count; } and increment a number's corresponding array member every time I see it, then you sort the array again and grab the number at the end.

well,...I think im too much of a brainlet for a job in IT...
>thought about stopping being a industrial mechanic
>tfw forever a mechanic

>please walk me through your thought process!

Protip, this is the important part.

wait a second, i may be retarded, but if i recall my statistics classes corect, the median is just the middle number.

i.e. array length / 2 if even, and (length/2)+1 if uneven.

so the only hard part is to come up with a sorting algorithm to merge these 2 arrays.

You don't need to merge anything, you just need to find the most common value in both arrays

you might want to go back to 5th grade and re-learn the difference between median and mode

no,finding the most common value would be the mode.

>i.e. array length / 2 if even, and (length/2)+1 if uneven.
We've seen enough. We'll be in touch.

Seriously though, it's length/2 if length is odd. If length is even, it's (arr[len / 2] + arr[len / 2 + 1]) /2

That's not called median.
Regards, youre retarded frogs.

Median is something else completely holy shit.

median is the middle number, wouldn't it be effectively the same?

no, dumbass

[1, 1, 1, 2, 3, 5, 9]

median == 2
mode == 1

>this fucking thread
lmao, thanks for the laugh
you know, people say that "Sup Forums was always shit", but now I'm sure that the posting quality has halved threefold in the past 4 years

>find the median of two sorted arrays
why? I can tell already this is a huge waste of time and my ability. I think I'll look for business relationships elsewhere.

Off the top of my head, you could have a pointer to the beginning and end of each array, then increment the smaller of the two beginnings and decrement the larger of the two ends back and forth until you find a middle value, in O(n)

Or you could just merge sort

How do you not know about time efficiency? Big O, Big Theta, etc. C'mon man, at least make it look like you know something about computer science. Data structures and Array Sorting is crucial, specifically how long it takes an algorithm to iterate completely.

a1 += a2
sort a1
if count a1 is odd, get (a1[round(count / 2)])
else get ((a1[count / 2] + a1[(count / 2) + 1]) / 2)
simple

/**
* @desc returns the median value of an array, assuming the array is a sorted number array
* @return number - median value of the array
*/
Array.prototype.median = function ( ) {
"use strict";
var length = this.length;
if ( length % 2 ) {
// odd length array
var middle = Math.floor( length / 2 );
return this[ middle ];
} else {
// even length array
var upper = length / 2;
var lower = upper - 1;
return ( this[ lower ] + this[ upper ] ) / 2;
}
}

Get the out our office you arrogant prick.
Consider yourself blacklisted.
*slams door behind your back*
*welcomes pajet or pajeta for half the price*

var newArr = arr1.concat(arr2).sort().

if (newArr.length % 2 === 0) {
return (newArr[Math.floor(newArr.length/2)] + newArr[Math.ceil(newArr.length/2)) / 2;
} else {
return newArr[Math.ceil(newArr.length / 2)];
}

Is this right?

It takes less then 15 minutes. They don't want to see actual code, you use psuedocode. They want to see if you really know how to properly implement algorithms.

not optimal
not optimal

shitters

Merge arrays and array length/2. What else would you need?

Forgot the ] at the end of the if statement

>get asked to write the bubble sort sorting algorithm on a whiteboard
>never heard of bubble sort until then
>they walk me through the sorting algorithm, but I can't catch on and fail to implement it correctly
>"something a little easier, then: sum all the primes below 2 million"
>they actually expect me to compute the primes myself
>I tell them I could sum the primes if I had them
>they aren't impressed, one guy clenching his jaw furiously while looking at me
>suddenly get the feeling that the next questions are just a formality
>my fears are proven true when they abruptly transition to the end of the interview
>can't even look them in the eyes as it's wrapped up
I've never felt so defeated.

being able to fluidly write that down on the whiteboard is all they're looking for. to filter out dumb cunts basically.

make a new array with the contents of both arrays and sort it again, grab the one in the middle

am I missing something?

>in your preferred language
Ok, Python.
import statistics
statistics.median(array1 + array2)

Is this supposed to be hard?

>am I missing something?
Yes you are not getting a job.

and this solution is linear time complexity

how can it be better than this?

you don't have to sort them again if you insert properly

If you're actively inserting based on conditional logic, you're basically sorting.

You know at the very least you can write a brute-force function to find out whether a number is a prime right? Then just call that on every number from 0 to 2 million. The time complexity is laughable but it werks for an interview.

if you're not a complete autist like most people here, go into consulting.

they need code monkeys like crazy so some wont even bother with interviews, you get free training and can cut past the bullshit interviews while working at top tier companies.

>in your preferred language, write a script that gets the current date and outputs it to a text file

Uh... ok...

>$ date > date.txt

They must have meant php or something...

But you didn't use a programming language to get the date, you used an already existing program and simply redirected its output to a file. You're supposed to know how to retrieve system time yourself.

your solution requires you to create a new array that is the size of both arrays combined.

This requires O(n+m) space and O(n+m) time, the optimal solution is O(log(min(m,n))) and requires no additional space

brainlets need not apply

median(array1, array2)

This is written in SekritScript, which is my personal language I created all by myself. You'll have to hire me if you want to know more, trade secrets and all.

maybe something like this? just off the top of my head this is what i would have done.

a = [1, 3, 33, 3344]
sorted = []
for i in a:
if (i < a[0]):
sorted.append(i)

return sorted

why dont you try
import job

That would be accomplished through some in-built library or function in the language of choice anyway.

isn't that the same as abs in python?

I never truly get if these posts are simply jokes or the truth.
I guess no matter what, it just at least be true for some person out there....

This is why you dont start programming in a high level language, skipping the building blocks.

They are all true for better or worse.

Anyone else fucking hate sorting algorithms? I'll just take 30 seconds to lookup a chart and pseudo code if I ever need to write one. I dont get these circle jerks of sorting algorthims and why they seem to be in every interview.
Data structures and design patterns should be considered much more important.

OP's question doesn't ask to sort, that's only a given of each array.
>return sorted
Your code will return an empty list. It's also unnecessarily verbose, you can replace it with list comprehension like so:
a = [1, 3, 33, 3344]
sorted = [i for i in a if i < a[0]]
But I have no idea what your code is supposed to do

I learned programming on my own as sort of a hobby in junior high and high school. My first compsci college course was a rude awakening.

The gaps in your knowledge from self teaching can be gigantic.
Sorting an array and finding the median isnt hard to hack together and show the logic if you are somewhat competent. If you self taught and literally never was taught the basics of arrays, you are going to be fucked

Kek'd stronkly
Wouldn't be surprised if this worked

Its puts people on the spot because who actually remembers sorting methods, but if you sit and think you should be able to get through it and explain your logic to the interviewer. And thats honestly all they want.

second guess.
a = [1, 3, 33, 3344]
b = [22,32,1,933]
c = []
d = []
for i in a:
if (i > 0):
c.append(i)

for i in b:
if (i > 0):
d.append(i)

s1 = abs(sum(c) - sum(d))

print s1

im sure by now they would be laughing at me too.

seeing how you react to this is part of the test. do you just blurt out the first stupid thing? do you think about it for a minute first? do you obsess over details? do you charge in blindly without thinking? everybody has strengths and weaknesses and that's what whiteboard problems are designed to find out

i would just end the interview on the spot if you said this, obviously you can cram as many libraries up your ass if you want but if you are too autistic to understand that this is meant to be a test of your algorithm-solving ability then there is no way you would be a good fit. basically

Is this normal? Am I going to have to do this whiteboard faggot shit to get a job?

that guy who imported the statistics module is already done and has a functional answer, unlike the other retards who still have to test and debug the sorting algo they copied off google

I can sort of get it if you just fluster and get super nervous during the interview, but if you can't solve problems like bubble sort or the one that OP mentions, then I don't know. It is basic middle school math....

am i just not understanding the problem? the median is the middle value of a set of numbers. so why not just concatenate the arrays and re-sort them, then divide its length by 2 and grab the number at that index.

it seems like the only heavy lifting involved would be if you have to do the sort yourself. i would opt for python's sort() method because it is fine for arrays of trivial length. if they were extremely large i would just say that i don't remember all the best sorting algorithms for this and that off the top of my head and would research some to find one that suits the initial conditions (two pre-sorted datasets) and implement it.

actually now that i talked through it a bit i might consider instead of CONCATENATING the arrays i might actually iterate through them and sort of "zipper merge" them, taking one from A, then one from B, then from A again, then from B again, and so on. then use a bubble sort. i think this would only work though if the two arrays are of similar length and have a similar statistical distribution

yeah yeah yeah and pajeet ranjeesh can slap together library after library and glue it all together with stackoverflow C+Ps. this is obviously not the point of the interview. you could say at the beginning that you might try to find a pre-built solution but the entire reason you are in that room in the first place is to test how well you can think through a basic but not trivial problem under pressure. if you were to just outright refuse to demonstrate your own personal problem solving skills then you will look like an arrogant autist

>copying
>anything

I don't think you understand.
They're running a business.
You're being hired to write their business logic so they can continue to make money in the future.
Nobody cares about the "right" way to do things so long as your code works and the product doesn't break at the end user level.

>looking at all elements
try again

I just got a job offer (in Scandinavia), I just had to answer basic general questions
>What layer would you put security?
>How would you use OOP to design and split up the code for vehicles?
>Do you know what micro services are?
>What are the benefits of micro services?

And a simple case at the end.
My 5 hours of leetcode did not help me.

>your labor is being used to generate profits for them in the future while they pay you a fraction of what your labor is actually worth.

Sweet. That's sort of my dream (except Barcelona or something). Did they do a background check? I have a felony for marijuana possession.

You are rare fucking example and a lucky sob I can tell you that much.

that's every job
if you think you can do better go start your own business using your skillset

>Background check
Outside of what is public information, that would be illegal in most cases. Only certain professions where it is needed. And then the police will issue a paper saying if you are allowed or not

this is why nobody takes python coders seriously.

Get an internship through IAESTE. Norway have a few of CS jobs through them. A lot do the foreigners stay after the "internship" is done.
Well paid.

no i dont think you understand. it's not about "right" or "wrong" ways, nor is it about the most efficient way to implement a singular solution to a trivial problem. it's about the interview determining if you have problem solving skills. you are going to work on things a lot harder than "find the median of 2 sorted lists", at which point it is appropriate to find pre-built libraries to take care of nitty gritty details like this. but you will be faced with challenges that require foresight, planning, understanding of how small pieces add up to the larger machine, and doing so under pressure. something that you cannot just import a library for. they obviously cannot get you to develop such a full application in a job interview, so they scale it down to test your ability to do so in a sandbox environment with something you should be able to come up with at least a rough solution for in under 20 minutes.

yes but its slow as fuck

t. unemployed neet

ok attempt #2:

how about summing the lengths of the arrays, and then starting at the beginning of both. read the first two values, call it current_A and current_B. discard the lower one. replace it with the next value from its respective source array. continue doing this for half the number of iterations as the sum of the two arrays. the lower number at that point should be the median

do you know what median is?

wow good one user

you don't get second chance champ we are on the clock here and there are other candidates waiting.
Better luck next time,the door is to your left thank you.

>barcelona

lol junior salary is 15k a year and senior is 33k

and the rent in barcelona it's 1k a month or smth
with electricity/water bills and food if you don't know how to cook, expect to spend around 1300-1500 euro a month

supposing you walk on foot to work

after you manage to magically survive as junior on 1100-1500 a month, 2700 will allow you to contract a loan for the next 40 years to get a house

Well, it's the first three results of searching my name on Google. So it's pretty public.
Definitely will look into that.

come on man i need this, feel my handshake, it's very firm

I knew some dude making bank over there. If what you say is too perhaps I'll consider remote work and just live there.

Change your name, it is not that difficult.

It is in my state. Your parents have to sign shit and you need affidavits of character and a full FBI background report.

NC.

? What? This is hard? This is sorted too... Isn't it literally if A,size%2 == 1
Then A[A/2 + 1] assuming we are using integers. if A.size%2 == 0 then A{A/2} + A[A/2 + 1] /2?

Maybe the middle value in the array?

it's not hard, but apparently hard enough
you're out, better luck next time

How do I make it go fast

I think he is making a java joke.

oh fk me. I saw the var. It is not java

my preferred language is user_lang_v43

here's the code

def find_median(array1, array2):
return Math.median(explode(array1, array2))

I myself have no desire to work in tech. I enjoy programming as a hobby to increase my knowledge of it. Im proud to be a self taught coder not owing one cent to any university.

>calls the tech industry garbage after being asked what the median is
>calls the first poster a retard
Sup Forums has gone to shit so quickly, it's unbelievable.
I thought summer time was over.

Fuck I can't do this. I don't think I've ever written a binary search yet.

I'm going to be one of those unemployeed unhirable neets aren't I

No you have to combine the arrays and then for median you will need to delete the end and last elements till you are left with the middle

Because these are arrays and not linked lists it'll involve a lot of repeated shifting of the array as soon as you remove the elemtns in the beginning

If you keep thinking that way you are.

not if the values are non-unique

I just spit out my water good damn

They say it is already sorted...

I don't get it, why not just take the array length then divide it by 2 and get that value? isn't that the median?