Amazon Interview Question for Software Engineer / Developers

Country: United States

Comment hidden because of low score. Click to expand.
of 1 vote

Logic is bit-wise and operation between networkaddress and IPaddress gives networkaddress.

1. Convert decimal dotted quad string to long integer
2. Convert a network address to a long integer
3. verify ip & net == net

Python code:

import socket,struct

def addressInNetwork(ip,net):
   ipaddr = struct.unpack('L',socket.inet_aton(ip))[0]//long int IPaddr
   netaddr,bits = net.split('/')	  //separate netaddress and mask
   netmask = struct.unpack('L',socket.inet_aton(netaddr))[0] & ((2L<<int(bits)-1) - 1)
   return ipaddr & netmask == netmask

returns true if it matches.

- pirate July 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

A network mask helps you to determine which portion determines the network id and which portion determines the node id.
class A- class B- class C-
Subnetting allows you to have multiple networks from among the class of networks which are A,B,C instead of having only one network from among the classes A,B,C. Here for class C the subnet mask is here as the first 3 bits are set you can have 8 subnets and 32 host addresses.
For class B you can have more subnets and more host addresses as allows you to have 32 subnets and 2^11 host addresses. It is also denoted as /27 as 27 bits are set in the network.

- vgeek July 30, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
of 0 vote

(Boolean) AND each address against the subnet mask then compare (SUB-tract).

If the two are equal then the address is within the network. AND in this case *masks off* the same number of lower bits from the network address and the address being tested. Thus the name "subnet *MASK*.

(In assembly language SUB-traction and comparison are effectively the same operation --- if different op-codes are present for both on a given processor it's likely that they only differ in which flags are set by the operation. A "zero" result from the subtraction only occurs if the two operand were exactly equal. Otherwise the result is either a positive or negative number; the precise representation of that number in the processor will depend on the architecture).

- Anonymous July 30, 2013 | Flag Reply

Add a Comment

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.


is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More


CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More