So hello guys! welcome to world's most selective university.
Stanford University.
For me this is the most beautiful school and college
I have ever been to as well.
And today's challenge is going to be coding question!
from IIT
or an MIT's
computer science exam.
So basically the plan is to challenge students with IIT and MIT questions.
And in addition Harnoor proposed an idea,
Students here go to venture capitalist for million dollars,
Why would they do it only for 100 dollars?
You're right!
Hi, can you please introduce yourself?
My name is Sourav
I'm a fourth year PhD student at Stanford.
Wow we gonna be crushed,
but where are you from by the way?
I'm from Chicago.
My name is Sahil and I'm a Sophomore here
at Stanford studying CS and math
And where are you from?
And I'm originally from Austin Texas,
Awesome!
You have taken both majors? Or which one is your minor?
Okay that is kind of undecidable
I'm interested in both and
we'll see what route I end up taking.
So you don't have to declare your major till 2nd year?
We don't declare until our 3rd year.
So yeah, there is a lot of flexibility.
Hi, I'm Christine nice to meet you
I am currently a masters student at electrical engineering department.
I'm from Urban California.
Hi, my name is Yoshub.
I did my UG in Maths and Physics
Now I'm working on masters in CS.
but theory. Not a lot of coding.
Brilliant.
And where are you from btw?
I'm from Denver, Colorado.
Hi I'm Sanjay
Where are you from?
I'm from Texas.
And what's your major? And which year are you in?
I am a sophomore and my major is in computer science.
So it would be kind of awkward if I fail. It's-
It's gonna be easy
What do you think? You do a lot of leetcode on second year or not?
I mean like
Yeah I just kind of started for recruiting this year.
So I had some leetcode experience
but curious to see how it translates now.
So we have five minute questions from two exams one is from IIT and one is from MIT.
Which one you think is difficult?
I think both are difficult.
Yeah but if you have to choose, which one you will choose? IIT from India and MIT you know!!
From Massachusetts.
Both are simple coding questions..
IIT!
IIT, okay go ahead!
Okay,so basically the question is for you that
You have given two strings
as binary
You need to add them up in Binary
And return the result in string.
Does that make sense?
So the first question you have is you have to add
Two Binary numbers
In string
and return in string as well.
the trick part is you have to handle carry, just like we do in normal addition.
Are the strings on same line?
It could be variable
It could be different? Okay.
Then what I might do is
I wanna loop backwards to the strings.
Right.
Just pre-process the strings that have the same length
then put zeroes.
Okay sounds good
Okay. You wanna just go ahead and write sudo code for it?
Or like whatever choice of language
Feel free.
At the beginning I will also start like a carry.
- And initialize that to be zero. - Gotcha, yeah.
yeah, exactly.
right on time.
What's the complexity?
What's the space complexity?
When we usually start by space complexity.
I mean you are storing the result in additional...
Right. But we don't really count that.
Okay so then just the carry.
Which is just...
Brilliant! Awesome.
We already have our first winner!
congratulations!
Stanford is known for startups. Do you have any startup story as well?
Because I have seen that every other student is working on one.
Is there a hype?
There's definitely a hype.
Y-Combinator is an accelator program where maximum students are from Stanford
for startups.
One is from IIT. One is from MIT.
Which one would you choose?
From their data structures class?
It's like a simple 101 data structures class.
I don't know.
- Let's go with... - India or US?
Which question do you think is easier?
I think both of them are probably hard but
Let's go India!
India! Okay, let's do it.
You are given let's say a string..
with numbers.
So let's say it's 101
first string
and you are gonna add it and then other string is
110
No need hardcode. Don't worry about syntax.
Just do pseudo code and don't worry.
Don't stress out.
You may convert these into an integer.
You can use a Boolean operator between them.
Okay. Let me give you a hint. A very preliminary hint.
Let's say they weren't strings.
How would you add it as a human?
So you have to keep objs as a carry
and add it in the place.
Yeah, yes! That's what you need.
How would you translate that into code?
Okay so, basically he got the right approach.
Had the right answer. The only sort of backfall was that
the code was not the most efficient one.
It was not the cleanest, right?
So we believe there was a better way to do it.
So that's why we wouldn't really have a
We wouldn't count as acceptable answer.
If you had done it in IIT, you wouldn't have get full marks.
- I see.. - AKA
We are gonna do it some sort of half discount and give him $50
But anyway, good stuff.
Good try!
So we have two questions. One from
MIT
from their data structures class
and other from IIT
from their data structures class as well.
Which one do you think is difficult?
IIT okay. I'll take that one.
So very popular question.
And should be pretty straightforward though the bruteforce way.
However we are looking for the most optimal one.
You know, you gotta be the higher standard.
So the second challenge is also straightforward.
You just have to tell true or false
if a number given is a power of 2.
For example, 4 is 2 to the power 2.
8 is 2 to the power 3
so they are power of 2 numbers.
Your task is to return true if that number is a power of 2.
If it's not a power of 2, you return false.
So I guess there's like a very cheap bruteforce way
which you could do is like you could just
like have your integer n
and like while say you haven't surpassed it.
Start iterating powers of 2
And if you hit the number
then you return true.
And if you like exceed that number,
then you return false. Cuz that means
you missed it.
An issue is if alpha is a 100,
this algorithm has
I mean the algorithm basically has a runtime of
log base 2 of n
- right? - Right, yeah yeah.
However we have even a more efficient solution.
Which is constant time and constant space.
Okay, so that's the benchmark.
That's the benchmark that you gotta get full credit at-
IIT data structures, algorithms 101!
I see, okay.
So.. dividing, right? Taking your number and dividing by 2
and then keeping this
Like a pointer and then dividing by 2 and so on.
- That will be constant space. - Yes!
So if it's like 15. That's 01- that's 8
Can I do one more minute?
So okay, here's the thing right. One final hint.
You wanna end it
with something that flips the bits.
And then check whether that end is equal to 0.
The solution is bit tricky.
You have to take that number
and do one and operation
with the number -1
and if the result is 0
then it is true.
This is the one liner solution.
That is an incredibly-
Yeah, but I mean, you made a really good try
and had a lot of approaches and thought it through.
So this shows that he's not cramming and not imprinting those solutions in head.
So we are gonna go ahead and give you $50 for this
generous attempt.
Many many congratulations for having an amazing attempt.
It proves that you are not cramming the question
and by the way
I have heard Stanford has amazing startup culture.
They don't run behind
FAANG and MAANG companies
Are you aiming for startup or..?
Not currently, altough it is on my radar.
I do have a friend of mine who is
I don't know exactly just- but he's gonna be working for a startup.
Startups here definitely seem very
modern and
very tight end. They enable you to
work on all sorts of development.
Yeah, I'll take the MIT one.
This is also a classic leetcode question.
Involving bit manipulation.
But it's also asked in MIT's
Data Structure and Algorithm class.
The question is pretty simple. You know if this is a power of 2,
you return true, if it is not, you return false.
So first of all, do you have any questions about the input?
And you have to do in the optimal solution.
Yeah, the most optimal way.
Let's give it a shot.
So do you have any questions related to the input by the way?
Yeah, so you said it could be a long
or an end.
So it's like, it's some whole number.
That's some positive whole number.
That's a good question. It is a positive number.
I mean it can't be negative anyway but it's not a fraction.
It's not a fraction, yeah yeah.
Right yeah, that is correct.
The 0 of n where is n is the number of bits.
However with this solution you would not get the full credit
at MIT.
Could you optimist this to be 0(1)?
Right? The most efficient way.
Most efficient...
So let me give you a hint.
What operations can you do in 0(1)
Like, it has to be some bit manipulations, right?
So basically now you have got to come up with an expression.
You can do in 001
So I am trying to see if there's some way we could
x or the bit or something
that we can extract at 1 and then check.
So...
good try I mean he made a real good effort
came up with a working solution
and knew the time complexity in detail
however it was not the most efficient again.
You won't get full marks for MIT.
But anyhow, congratulations.
That's why I am at Stanford, not MIT.
And..
n-1
equals zero.
It was just a one liner solution.
Congratulations. Nice try.
So it was tricky because you have to create the expression.
BUt what do you think? Do you do intensive leetcode in college?
To be honest, not really. I have heard about leetcode
and I have tried a few questions
I guess it's more like
I am just interested in problem solving more
I am not trying to do too much leetcode
we'll see. Maybe I need to start now.
And what about startups? I have heard that Stanford students
do a lot of startups and it's a culture.
It's a hype, right?
So do you also plan to get into one?
Yeah, I mean, if there's a specific problem that I see
that actually needs work on or that needs to be solved,
then I think startup would be a great option.
And
yeah, I think it's important to like, you know
separate yourself from the hype
and make sure you actually are solving real problems
If there is a real problem that I do see that I can solve in the future
then I would definitely hop on the train.
I actually know one person
or two people who took one of their treehacks projects
and they went to Y-Combinator and they are now
Hackathon to Y-Combinator?
Having millions of dollars!
They got 1 milion dollar funding.
Are you taught about startups at school?
I mean there's a lot of classes that are exclusively focused on startups.
The student culture is definitely driven by that.
So I think a lot of people automatically are interested.
Brilliant.
So we have two questions. One from MIT
from their data structures class
and other question- they are simple enough.
And other question from an Indian University called IIT.
So which one you think is easier and we will give you that one.
MIT.
Sure, let's do it.
I have heard of IIT!!
That's crazy!!
So the question is - given a number- let's say 101
is addition of two numbers in string.
So the TLDR is you are given two strings in binary
and you are supposed to add them and return the sum as binary.
But in string.
Yeah, as a string.
- They are binary but- - 1 and 1
For each digit or like character,
I'm gonna get
the...
number
of this and so I just do like
for example, 1-0
or I can-
or I can also say like
okay, if it's 1 then just
convert into 1.
Yes, you can call it an integer.
Pretty much just convert.
Carry and then we'll set it to like
0 at first. So if it's 2 then we set it to 1.
- That is correct. - And then we just have
another string
where...
Yeah, you got it right. Cool!
So what's the time complexity of this?
The big 0 of?
The big 0 of...
On iteration you can go through both the strings.
So would it be the big 0 of just
the length of the larger string?
Would it be double that or just that?
It would be just that.
Okay. That makes sense.
Awesome!
First of all congratulations.
Lot of students do startups at Stanford. Do you have friends
selected for Y-Combinator?
I have some friends doing startups
but I don't really know what they are upto too much
honestly.
Do you do leetcode regularly? How these kind of problems were taught?
I think only in one class
But I have recently been trying to find a job
so I have been doing a bit of leetcode.
Awesome but congratulations
on winning 100 dollars.