What are Jow Forums's favorite programming interview questions?

What are Jow Forums's favorite programming interview questions?
The ones you would ask if you were interviewing a candidate?
Math teasers are welcome too. I'll start.

>You flip a fair coin many times until either a pattern of HHT or HTT occurs.
>Which of these is more likely to occur, or are they the same?
>What is the probability to get each pattern?

Attached: 1545436045397.jpg (504x389, 27K)

Other urls found in this thread:

github.com/DaveGamble/cJSON
twitter.com/NSFWRedditGif

Same probability. So 50% for each.

hht

it's 1/8 for each pattern dumbass
hhh
hht
hth
htt
thh
tht
tth
ttt

Attached: 85bf715bceb9437e2b0ed5f9dfee88b2c9037b233861a7e92d9933011df81981.jpg (680x695, 34K)

You have an array with all the values between 1-100 in it, except for one that is missing.
How do you find it?

HHT is more common, it will occur twice as often as HTT. This can be easily observed using a simple markov chain.

let state = {
HHT: 0,
HTT: 0,
HH: .25,
HT: .25,
TH: .25,
TT: .25,
};

for (let i = 0; i < 1000; i++) {
state = {
HHT: state.HHT + state.HH * .5,
HTT: state.HTT + state.HT * .5,
HH: state.HH * .5 + state.TH * .5,
HT: state.TH * .5,
TH: state.HT * .5 + state.TT * .5,
TT: state.TT * .5,
};
}

console.log(`HHT: ${state.HHT}, HTT: ${state.HTT}`);

So because the hht option has 2 consecutives in the first 2 positions I’m guessing it’s more likely to occur. Because you will get an h 50% of the time and then have a 25% of getting hht but you will get a t 50% of time and have 0% of getting htt. Mathlet here so someone smart weigh in.

const findMissing = arr => 5050 - arr.reduce((a, b) => a + b, 0);

My mathlet brain tells me that P(HTT) = P(H)P(T)P(T) = 1/8 which is the same as P(HHT).

>has 2 consecutives in the first 2 positions I’m guessing it’s more likely to occur
incorrect

No joke.
Perl 6 and Java 9.

Attached: 1547317467565.png (1128x1002, 105K)

what is the answer then user, i think his logic was sound

isnt it .5*.5*.5 for both?

The absolute state
Why don’t you prove it? I’d like to be amused.

I already did.

each coin toss is an independent event so the fact that there are two consecutive tosses with the same outcome is just a coincidence. the sequences {hh,ht,th,tt} are all equally likely

This is bait right?

Brainlet here, i know i am wrong but i just wanna try.
H or T = 50%
HH, HT, TH or TT = 25%
HHT, HHH, HTT and so on = 12,5%

The correct answer has been posted 6 replies in. Why are you brainlets still arguing about this?

Everything on the various code testing platforms is terribly worded.

Look at this bullshit. This is actually an easy question. But it's been ten years since I graduated and I spend more time googling this syntax and trying to understand the question than answering it.

Attached: bullshit.png (859x334, 36K)

what is this picture from?

Think about it. You’re going to need to get heads to complete either set, so take the first heads for granted because the odds are equal. Now if your next toss is heads you are guranteed to toss an HHT eventually because you have locked in the HH and if you continue tossing heads you will still have HH. If your 2nd toss is tails (50%) you would need your 3rd toss to be tails (50%) or restart with just the first H locked in. So after first throw heads you are 50% to get hht and 25% to get htt. In other words 2/3 hht 1/3 htt

not him but looks like hackerrank.

>ITT: pointless trivia questions that companies ask because they think they'll find the smartest candidates this way but the reality is that they only get people who cram leetcode / hackerrank / codeality and coincidentally might actually be good at the job

Attached: rhel.png (1270x679, 473K)

I never crammed leetcode or hackerrank. All you have to do is pay attention in class.

Except your wrong, they don't teach you how to read and then immediately solve shit like It's not hard and anyone can learn it, my point was that it's not reflective of th eactual job so you end up having to learn "cs interviewing" and "actually being a good software engineer" and they're entirely separate things.

Yes they do. That notation is in literally any discrete mathematics course. Pay attention in class buddy.

1. Sort the array in O(nlogn).
2. Scan the sorted array checking for
abs( array[k] - array[k-1] ) > 1.

array[k-1] +1 is the missing number

what language is this?

Javascript

Confirming it's Hackerrank, which commonly shows up as a recommended place to study for interviews.

The issue is that's not a bait tier cherry picked example. A high portion of their questions are written like that. I'm half expecting you could up a version of Fizzbuzz referring to three obscure mathematical formulas and quotes from a Latin textbook.

Again, pay attention in class. This is notation taught in introductory courses.

5050 - sum of values in array

I can't wait to use all the maths from my CS degree interviewing for a job ten years later so I can forget it again.

Yeah, who would ever need math?

I try very hard to avoid the temptation of asking tricky logic puzzles that don't actually relate at all to the job being interviewed for. As far as technical questions go, I've found the best ones have come from asking other programmers to take note of any time they've come across a problem in their daily work that had a satisfying solution and share them with me.

Could all these fucking autists write an answer to that question? Everyone was happy to write an answer for

my customer asks me for something like this every day. why is Jow Forums struggling with this?

How would your friends describe you?
3 adjectives and why.

Here you go. Uses 0-based indexing instead of 1-based since this is probably your homework and I'm not going to do it all for you.

function applyTwice(mapping) {
const f = (i) => mapping[i];
return mapping.map((_, i) => f(f(i)));
}

>O(n(logn + 1))
>Task can easily be done in O(n)

Attached: brainlet.png (226x223, 7K)

It hardly fucking matters if N = 100

Well done. You're now clear for a front end position in our organisation. Your first job is for phone posters to get a bit interstitial recommending the app.

I won't take anything less than 350k a year.

What's the biggest number below 1 billion that can be created by multiplying 3 prime numbers?

>You have an array with all the values between 1-100 in it, except for 5 numbers that are missing.

Where is your god now?

999999998 = 2 * 691 * 723589

How much wood would a woodchuck chuck if a woodchuck could chuck wood?

1/8
Same
1/4

My bad I made it too easy. Find the largest product of two prime numbers that add to a prime below 1 billion.

I have an idea, it uses binary search. Step 1, go to the center of the array, in this case index 50, and then check if the index matches the number. If a number less than 50 was removed, the number at index 50 would be 49 and therefore the number removed was somewhere between index 0 and 50. Then you jump to index 25 and do the same process and essencially so a binary search checking if the index of the array matches the value.

let me know if this was an alright solution

no its common sense there are two sides 100% / 2 = 50%

nigga what the fuck

999999191 + 2 = 999999193
999999191 * 2 = 1999998382

how the actual fuck would you do this with just a paper

If we look at 3 consecutive throws o its own, propability of throwing HTT and HHT are the same.
But let us consider throw before our initial three
_HTT --> HHTT; THTT
and
_HHT --> HHHT; THHT
we see that that to get HTT you need a consecutive sequence of 4 throws THTT otherwise HHTcomes first.

So i would conclude HHT c
Has higher propability of showing up first. Butbeing brainlet as i am now i would do quick simulation to find out estimate of propability with monte carlo method.

XOR all of the values in the array and then XOR the result with 1 to 100.

Create an array of 100 bools, set true to all values found on the original array, check the bool array for all false values.

Attached: 1528678312193.png (851x846, 573K)

>"user, please scrape this HTML using regular expressions."
There are 3 outcomes:
- not knowing you can't parse nested structures with regular parsers
- thinking it is ok to use various extensions of regex engines in a problem like this
- stating that regex isn't the right tool
Unless the candidate decides for option c it's "You'll hear from us".

>"user, why shouldn't you use XML as a key value storage?"
The answer is that it can't natively represent a hashtable, unlike JSON.

>"user, please tell us how you would design a plugin system for our data-heavy application."
Candidate attempts to embed some scripting shit -> "You'll hear from us."

>The answer is that it can't natively represent a hashtable, unlike JSON.
foobar
foobar
foobar
foobar
?

>n lookup when parsed, unless you copy it into a hashmap
no

How is that different than JSON...

JSON objects are hashtables

JSON is a string you have to de-serialize it into whatever you want.
You could do this with the XML I posted.

whats the solution to #2?

As an example here is a popular JSON library where objects are NOT hash tables and have O(n) key access.

>You could do this with the XML I posted.
You would require manual work, tho. (Noteworthy) json parsers do this automatically.

I forgot link
github.com/DaveGamble/cJSON

a) you didn't post it
b) it's probably garbage as performance is concerned

write a fizzbuzz

Attached: 1543745387561.jpg (600x484, 25K)

It even states so
>cJSON aims to be the dumbest possible parser that you can get your job done with.

So? The JSON standard doesn't specify.
Initial parsing is naturally going to have to scan string so the xml is fine from that point of view.

There are more than 6 replies. They are all contradicting each other, so which one is it?

Given an infinite grid of resistors each with R ohms, find the equivalent resistance between any two resistors a knights move away from each other

I don't understand the problem
Everything in that picture is pretty standard, you learn these notations during the first day in college

>he thinks initial parsing is the important part
More often then not, it's not. Modifying and looking up data is. Although, since you're noting it, XML (as described by the standard) is way slower to parse.

>More often then not, it's not.
Which is why after parsing you'd put it into whatever represenation you wanted.
JSON objects are not hash tables like you said they are serialization of key->value object.

>JSON objects are not hash tables
they are though in every non-trash tier parser

Oh, also, they are in every dynamically typed language once serialized.

Teach me, Sensei!

#include

int main()
{
int values[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, /*43, */44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100};
int missing = 0;

for (int i = 0; i < 99; ++i)
{
missing ^= values[i];
}

for (int i = 1; i

No, shishou. I don't doubt that it works, but why? Like, how? I did it in my head for 5 numbers and it seems kind of similar to the sum subtraction method and it makes a little sense to me, but I can't put my finger on the core idea.

Sorry for being so vague, but basically I'm asking for the proof.

>hht, hth, thh
>tth, htt, tht
user, how fucking retarded are you exactly?

Shit, I'm a fucking idiot, the XORs cancel out. Fuck.
Thanks a lot, though.

I'd ask a variant of the largest increasing subsequence problem and see if they can provide answers using naive recursion and using dynamic programming.

Give a definition of a language and ask if it's regular, context-free, etc.

great answer, thanks

Yes, it's like you XOR a value to "store" it and then you XOR it again to "remove" it. If you stored all 1-100 values, and you removed 1-100 except one, the remaining value is the missing one. This is, obviously, not the proof that it works, whoever wants to know exactly how it works needs to study the properties of XOR.

Sankyuu, masuta.

XOR is a binary bitwise operation that returns a variable whose bits are as follows:
pad zeroes to larger variable
linear traverse both
->if left bit is different from right bit
-->place 1 on output variable at current offset
->else place 0 on output variable at current offset

Same chance
.125 for each

suppose the last three tosses are [a,b,c] with c being the last toss.
a=h is given so we can ignore a and only focus on the last two.
b=h guarantees an eventual hht (1/2) chance of this.
b=t gives either a htt (1/4)
or a hth which resets to a=h (1/4)

so the probability of hht = 1/2 + 1/4*1/2+1/4*1/4*1/2...
which is a sum where each element makes 1/2 after n number of reset cases starting at n=0.

This is a geometric series with a common ratio of 1/4 and a first term 1/2. Plugging this into the infinite sum formula a1/(1-r) gives (1/2)/(3/4) = (1/2)*(4/3)=4/6=2/3

So the chance of hht=2/3 and chance of htt = 1/3.

>which is a sum where each element makes 1/2
Sorry I'm phoneposting and writing like a retard, I mean that it gets h=b (1/2 chance) after n resets.

Autism
Big brain and big penis

Attached: Laughing_Whore.jpg (762x900, 161K)

He's right you idiot

anyone who thinks HHT and HTT are equally likely is a brainlet who needs to get the fuck off this board.

Attached: 1542609702333.jpg (623x702, 177K)

Hard to believe, but good for you if true - most of us get, 'i used to have a button that did all the shit the company is trying to get rid of, can you add it pls lulz'- Karen fr accting