abhinav.thegame
BAN USER
- 1of 1 vote
AnswersProgramming Challenge Description:
- abhinav.thegame in United States
Develop a service to help a client quickly find a manager who can resolve the conflict between two employees. When there is a conflict between two employees, the closest common manager should help resolve the conflict. The developers plan to test the service by providing an example reporting hierarchy to enable the identification of the closest common manager for two employees. Your goal is to develop an algorithm for IBM to efficiently perform this task. To keep things simple, they just use a single relationship "isManagerOf" between any two employees. For example, consider a reporting structure represented as a set of triples:
Tom isManagerOf Mary
Mary isManagerOf Bob
Mary isManagerOf Sam
Bob isManagerOf John
Sam isManagerOf Pete
Sam isManagerOf Katie
The manager who should resolve the conflict between Bob and Mary is Tom(Mary's manager). The manager who should resolve the conflict between Pete and Katie is Sam(both employees' manager). The manager who should resolve the conflict between Bob and Pete is Mary(Bob's manager and Pete's manager's manager).
Assumptions:
There will be at least one isManagerOf relationship.
There can be a maximum of 15 team member to a single manager
No cross management would exist i.e., a person can have only one manager
There can be a maximum of 100 levels of manager relationships in the corporation
Input:
R1,R2,R3,R4...Rn,Person1,Person2 R1...Rn - A comma separated list of "isManagerOf" relationships. Each relationship being represented by an arrow "Manager->Person". Person1,Person2 - The name of the two employee that have conflict
Output:
The name of the manager who can resolve the conflict Note: Please be prepared to provide a video follow-up response to describe your approach to this exercise.
Test 1:
Test Input
Frank->Mary,Mary->Sam,Mary->Bob,Sam->Katie,Sam->Pete,Bob->John,Bob,Katie
Expected Output
Mary
Test 2:
Test Input
Sam->Pete,Pete->Nancy,Sam->Katie,Mary->Bob,Frank->Mary,Mary->Sam,Bob->John,Sam,John
Expected Output
Mary| Report Duplicate | Flag | PURGE
IBM Software Engineer / Developer Coding Java Python String Manipulation - 0of 0 votes
AnswersThis questing was something related to parse trees. I really don't remember the semantics but needed to extract the complete sentences from the provided parse tress.
- abhinav.thegame in United States
Input: A full sentence: (S (NP (NNP James)) (VP (VBZ is) (NP (NP (DT a) (NN boy)) (VP (VBG eating) (NP (NNS sausages))))))
Output: James is a boy eating sausages
Input: (NNS Sausages)
Output: Sausages
Input: (NP(DT a) (NN boy))
Output: a boy| Report Duplicate | Flag | PURGE
IBM Software Engineer / Developer Java - 0of 0 votes
AnswersYou will be given a sequence of passages, and must filter out any passage whose text (sequence of whitespace-delimited words) is wholly contained as a sub-passage of one or more of the other passages.
- abhinav.thegame in United States
When comparing for containment, certain rules must be followed:
The case of alphabetic characters should be ignored
Leading and trailing whitespace should be ignored
Any other block of contiguous whitespace should be treated as a single space
non-alphanumeric character should be ignored, white space should be retained
Duplicates must also be filtered - if two passages are considered equal with respect to the comparison rules listed above, only the shortest should be retained. If they are also the same length, the earlier one in the input sequence should be kept. The retained passages should be output in their original form (identical to the input passage), and in the same order.
Input: For each test case a single line comprising the passages (strings) to be processed, delimited by | characters. The | characters are not considered part of any passage.
Output: A single line of filtered passages in the same |-delimited format.
Input1: IBM cognitive computing|IBM "cognitive" computing is a revolution| ibm cognitive computing|'IBM Cognitive Computing' is a revolution?
Output1: IBM "cognitive" computing is a revolution
Input2: IBM cognitive computing|IBM "cognitive" computing is a revolution|the cognitive computing is a revolution
Output2: IBM "cognitive" computing is a revolution|the cognitive computing is a revolution| Report Duplicate | Flag | PURGE
IBM Software Engineer / Developer Java
Not in Java, but this one's in Python
import re
def clean_input(text):
#non-alphanumeric character should be ignored
text = re.sub('[^a-zA-Z\s]', '', text)
#Any other block of contiguous whitespace should be treated as a single space
#white space should be retained
text = re.sub(' +',' ',text)
#Leading and trailing whitespace should be ignored
text = text.strip(' \t\n\r')
# You probably want this too
text = text.lower()
return text
def process(text):
#If they are also the same length, the earlier one in the input sequence should be kept.
# Using arrays (can use OrderedDict too, probably easier and nice, although below is clearer for you.
original_parts = text.split('|')
clean_parts = [clean_input(x) for x in original_parts]
original_parts_to_check = []
ignore_idx = []
for idx, ele in enumerate(original_parts):
if idx in ignore_idx:
continue
#The case of alphabetic characters should be ignored
if len(ele) < 2:
continue
#Duplicates must also be filtered -if two passages are considered equal with respect to the comparison rules listed above, only the shortest should be retained.
if clean_parts[idx] in clean_parts[:idx]+clean_parts[idx+1:]:
indices = [i for i, x in enumerate(clean_parts) if x == clean_parts[idx]]
use = indices[0]
for i in indices[1:]:
if len(original_parts[i]) < len(original_parts[use]):
use = i
if idx == use:
ignore_idx += indices
else:
ignore_idx += [x for x in indices if x != use]
continue
original_parts_to_check.append(idx)
# Doing the text in text matching here. Depending on size and type of dataset,
# Which you should test as it would affect this, you may want this as part
# of the function above, or before, etc. If you're only doing 100 bits of
# data, then it doesn't matter. Optimize accordingly.
text_to_return = []
clean_to_check = [clean_parts[x] for x in original_parts_to_check]
for idx in original_parts_to_check:
# This bit can be done better, but I have no more time to work on this.
if any([(clean_parts[idx] in clean_text) for clean_text in [x for x in clean_to_check if x != clean_parts[idx]]]):
continue
text_to_return.append(original_parts[idx])
#The retained passages should be output in their original form (identical to the input passage), and in the same order.
return '|'.join(text_to_return)
assert(process('IBM cognitive computing|IBM "cognitive" computing is a revolution| ibm cognitive computing|\'IBM Cognitive Computing\' is a revolution?') ==
'IBM "cognitive" computing is a revolution')
print(process('IBM cognitive computing|IBM "cognitive" computing is a revolution| ibm cognitive computing|\'IBM Cognitive Computing\' is a revolution?'))
assert(process('IBM cognitive computing|IBM "cognitive" computing is a revolution|the cognitive computing is a revolution') ==
'IBM "cognitive" computing is a revolution|the cognitive computing is a revolution')
print(process('IBM cognitive computing|IBM "cognitive" computing is a revolution|the cognitive computing is a revolution'))
Thanks ashish for your code. But the output of your code is: James
is
a
boy
eating
sausages
Instead it should be: James is a boy eating sausages.
Thank you NoOne for your comment. Is there any online compiler available for this language that I can test your pseudo code at? That will help me to know your code more and convert it to python or java
- abhinav.thegame October 13, 2016@NoOne: I am sorry to ask this, but is this java??
- abhinav.thegame October 13, 2016
RepMorrisHelen, Speech writer at Micro Design
I am a speechwriter who works directly with senior executives or leaders to determine what points, themes, positions, or messages ...
Reptargienaron, Public relations coordinator at Total Quality
I am a public relations coordinator . Planning publicity strategies and campaigns. writing and producing presentations and press releases. I explore ...
RepWhyable is an agile team of Software Specialists with vast experience across multiple languages.We will help you to define ...
Repzhenhsiungz, Android test engineer at AppPerfect
I am a financial planner . I help individuals and corporations meet their long-term financial objectives. I enjoy spending my spare ...
RepEdwards IVF Surrogate is one of the best & most successful provider of surrogate services.We provide moral, emotional, ethical and ...
RepLove is the spice of everyone’s life. Love adds charm and excitement to the monotonous and boring life. If ...
RepOur mission is to provide informative and Self Improvement advice to help people live their lives better set definite goals ...
RepLooking for the best child development center in Charlotte? Pal A Roos provide summer camp for children Charlotte. Our experienced ...
RepHvactools, maintenence engineer
HVACTOOLS.co.nz now stocking all Javac and Spectroline HVAC and Refrigeration products. Including Recovery Units, Vacuum Pumps, Leak detectors ...
RepTerryDBonner, Employee at Electronic Arts
Maintained accurate personal records on maintenance crews and technical records on weekly insulation production.Have years of Installation and servicing ...
RepDeveloped several new methods for licensing g.i. joes in Los Angeles, CA. Spent high school summers creating marketing channels ...
RepDorothySanders, Accountant at Amazon
Hello, I am an Engineering manager. I love my work. I also love to read news articles related to the ...
Rephcr689121, Data Engineer at Autonomy Zantaz
Harrison is an electronic data processor experience in electronic data processor and Promotion. I enjoy providing health resources and how ...
Hello NoOne,
- abhinav.thegame October 17, 2016Thank you very much for your response. Could you please post the answer either in Java or Python???