d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Fun Interview Question > For A Software Engineer Job
Prev123Next
Add Reply New Topic New Poll
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 15 2016 06:25pm
Quote (AbDuCt @ Mar 15 2016 07:22pm)
I thought that as well. The catch that screwed with me is everyone must know the superstar. So even if a person knows no one, everyone must know that person.


i think that only matters if it's possible nobody is the superstar? the way you worded it, i assumed he must exist.

even then, it sounds straight forward?

first loop: ask everyone if he knows nobody. if you come across nobody or a second person, then superstar doesnt exist.

second loop: we found exactly one person who knows nobody. ask everyone else if they know him.

This post was edited by carteblanche on Mar 15 2016 06:28pm
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 15 2016 06:30pm
Quote (carteblanche @ Mar 15 2016 08:25pm)
i think that only matters if it's possible nobody is the superstar? the way you worded it, i assumed he must exist.

even then, it sounds straight forward?

first loop: ask everyone if he knows nobody

second loop: ask everyone else if they know the person from earlier.


That's not O(n) though is it? I suck at big O notation. It also becomes a question of what if multiple people don't know anyone. You'd have to do a sub iteration asking people for each N people who don't know anyone.

This post was edited by AbDuCt on Mar 15 2016 06:32pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 15 2016 06:31pm
Quote (AbDuCt @ Mar 15 2016 07:30pm)
That's not O(n) though is it? I suck at big O notation.


it's a constant factor, so yeah it's O(n)
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 15 2016 06:33pm
Quote (carteblanche @ Mar 15 2016 08:31pm)
it's a constant factor, so yeah it's O(n)


I see. Shows how much I know about O notation.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 15 2016 06:43pm
Quote (AbDuCt @ Mar 15 2016 07:30pm)
It also becomes a question of what if multiple people don't know anyone. You'd have to do a sub iteration asking people for each N people who don't know anyone.


as soon as you find a second person who doesn't know anyone, you know neither is the superstar, and more broadly, you know there is no superstar. it's a contradiction for "everyone knows the superstar"

This post was edited by carteblanche on Mar 15 2016 06:45pm
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Mar 15 2016 06:52pm
Quote (carteblanche @ Mar 15 2016 08:43pm)
as soon as you find a second person who doesn't know anyone, you know neither is the superstar, and more broadly, you know there is no superstar. it's a contradiction for "everyone knows the superstar"


Yea I guess you got me there. I hate word problems.
Member
Posts: 3,476
Joined: Jul 20 2015
Gold: 651.00
Mar 15 2016 10:57pm
Quote (Ideophobe @ Mar 15 2016 05:56pm)
i answered it

hint - tom did know the address



Yes but I'm not tom so how do I find out how old bobs daughters are if I don't know the address?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 15 2016 11:14pm
Quote (spt_94 @ Mar 15 2016 11:57pm)
Yes but I'm not tom so how do I find out how old bobs daughters are if I don't know the address?


do you need to know it? or is its mention significant enough?
Member
Posts: 62,215
Joined: Jun 3 2007
Gold: 9,039.20
Mar 15 2016 11:48pm
Quote (spt_94 @ Mar 15 2016 10:57pm)
Yes but I'm not tom so how do I find out how old bobs daughters are if I don't know the address?


There's only one address really that fits that criteria, even if you don't know it, you can write a function to check a range of addresses against those requirements.
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Mar 16 2016 12:40am
Quote (j0ltk0la @ Mar 16 2016 12:48am)
There's only one address really that fits that criteria, even if you don't know it, you can write a function to check a range of addresses against those requirements.


Tom knows the address. Which means the sum of the ages doesn't help him. This means that off all the possible sums of x y z, the answer will be selected from the subset of summations which are not distinct. From these selections, Bob points out that you can tell who the oldest is by her hair color. Meaning the highest number of the set is distinct. The oldest is not a set of twins, because Bob says his oldest singular.
1 1 36 = 38
1 2 18 = 21
1 3 12 = 16
1 4 9 = 14
1 6 6 = 13
2 2 9 = 13
2 3 6 = 11
3 3 4 = 10

And now you have two candidates: 1 6 6 and 2 2 9. But we already know that the oldest is distinct. So the answer is Bob has 2 year old twins and a 9 year old.
Go Back To Programming & Development Topic List
Prev123Next
Add Reply New Topic New Poll