## Councyl Interview Question for Software Engineer Interns

Country: United States
Interview Type: Phone Interview

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

The goal is to build a list of all GOOD ids and all BAD ids and the remaining UNKNOWN ids.
I'd start by putting all IDs found on GOOD rows into the good list.
Then I'd remove all good ids from the BAD rows.
If any bad row has only a single ID remaining after the known good ids are removed, that id must be bad, so add it to the BAD list.
If any remaining BAD rows still have multiple IDs, those are the ids that you cannot reasonably conclude as BAD or GOOD so they would be the MULTIPLE MAPPING results.
If any BAD rows have 0 IDs after the known good ids are removed then that would be the NO CONSISTENT case.

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

Same logic as the other answer, but correct implementation. The other answer will result in multiple answers being printed in certain cases, and will in fact give an incorrect answer for certain cases as well.

Eg:
GOOD,11,12

will give multiple mapping in the other code, where as there is a distinct answer.

``````def main():

n = int(input())

good_nums = set([])

all_nums = set([])
for _ in range(n):
s = input().strip().split(",")

tag = s[0]
nums = [int(k) for k in s[1:]]

all_nums.update(nums)

if tag == "GOOD":
for k in nums:
else:

if ans:
print(ans)
else:
for i in sorted(all_nums):
final_tag = "GOOD" if i in good_nums else "BAD"
print(str(i) + ": " + final_tag)

ans = None

# We don't return from here because it is possible that
# some other tagging makes the answer "NO CONSISTENT"
# which is stronger than multiple mapping
ans = "MULTIPLE MAPPING"
# We can return from here since a solution does not exist
return "NO CONSISTENT"

return ans

if __name__ == "__main__":
main()``````

Output:

``````2
MULTIPLE MAPPING``````

``````2
GOOD,10,11,12
NO CONSISTENT``````

``````2
GOOD,10,11
10: GOOD
11: GOOD

``````3
GOOD,11,12
11: GOOD
12: GOOD

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

I think the thing to realise here is that if there are multiple IDs that could be bad, then there are multiple mappings - any one of them could be bad to validate everything (leaving the others in a state of "not enough info").

With that in mind, you need to construct two sets - one of things that must be good, because they were in a GOOD class, and one of things that could be bad, because they were in a BAD class.

Python 2.7

``````inp = " "

good = set()
#Parse input in good and potential bads
while inp is not "":
inp = raw_input()
csv = inp.split(",")
classification = csv[0]
ids = [x.strip() for x in csv[1:]]

if(classification == "GOOD"):
good.update(ids)
else:

#Get the possible bads through set subtraction
print "NOT CONSISTENT"
print "MULTIPLE MAPPING"
else:
for g in sorted(good):
print "{}, GOOD".format(g)
else:
for g in sorted(good):
print "{}, GOOD".format(g)``````

Name:

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

### Books

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

### Videos

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.