27.10.2014 Views

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Solutions</strong> to Chapter 11 | System Design <strong>and</strong> Memory Limits<br />

29 public int getID() { return ID; }<br />

30 public int getMachineID() { return machineID; }<br />

31 public void addFriend(int id) { friends.add(id); }<br />

32<br />

33 // Look up a person given <strong>the</strong>ir ID <strong>and</strong> Machine ID<br />

34 public Person lookUpFriend(int machineID, int ID) {<br />

35 for (Machine m : server.machines) {<br />

36 if (m.machineID == machineID) {<br />

37 for (Person p : m.persons) {<br />

38 if (p.ID == ID){<br />

39 return p;<br />

40 }<br />

41 }<br />

42 }<br />

43 }<br />

44 return null;<br />

45 }<br />

46<br />

47 // Look up a machine given <strong>the</strong> machine ID<br />

48 public Machine lookUpMachine(int machineID) {<br />

49 for (Machine m:server.machines) {<br />

50 if (m.machineID == machineID)<br />

51 return m;<br />

52 }<br />

53 return null;<br />

54 }<br />

55<br />

56 public Person(int iD, int machineID) {<br />

57 ID = iD;<br />

58 this.machineID = machineID;<br />

59 }<br />

60 }<br />

2 0 1<br />

<strong>Cracking</strong> <strong>the</strong> <strong>Coding</strong> <strong>Interview</strong> | Concepts <strong>and</strong> Algorithms

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!