## Software Engineer / Developer Interview Questions

- 1of 1 vote
Programming Challenge Description:

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

- 0of 0 votes
We tend to use computer to solve practical problems that actually earns or save dollars. Here is something that happens across the stock exchanges : people buy and sell stocks.

We generally use automated intelligent systems to buy and sell stocks. That part is too much mathematics, and beyond scope of this interview. There is another part. Suppose the system issues a buy order : buy 1000 Microsoft stock. Now, there are more than 1 ( in fact 10 ) active exchanges from where we can buy MSFT. There is a slight price delta, which keeps changing over time. There is another problem. In each stock exchange, prices are stacked, that is :

1. For first 100 stocks prices are 55$.

2. Next 200 stocks, prices are 55.2$.

... etc, and you got the idea. Even this stacks are changing over time.

Thus, here is the problem to solve. Design and implement a system such that one can buy n stocks with minimal price.

Also, in the same spirit, the same system should be able to sell n stocks with maximum payoff possible.

This is a non trivial problem, for Quant systems.

There are always k no of exchanges to hit.

- 0of 0 votes
This 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.

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

- -1of 1 vote
For a given string sentence, reverse it.

Input : Hello World

Output : Dlorw Olleh

Input: How Are You Doing Today

Output: Yadot Ginod Uoy Era Woh

- 0of 0 votes
You 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.

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

- 1of 1 vote
Hey guys, I was asked this question on Bloomberg's pre-interview screening exam and I was wondering how to go about it.

Find the tightest asymptotic bound for:

T(n) = n(T(n/2)^2)

so far I was able to get it to look like this (not sure if correct):

T(n) = 1 / (1 + T(n/2)^2)

From then I made a recursion tree which led me to think that T(n) might be exponential in this case. Do you have any idea where could I go from here? Do you think this has no tight asymptotic bound?

- 0of 0 votes
why we need interface ( pure virtual function or abstract class) in c++?

Instead of having abstract class we can have a base class with virtual function defined in it, and override that virtual function in derived class.

what would be the advantage and disadvantage with the above approach ( except we can create the object of the base class)?

- 0of 0 votes
f(n)=n⁄2 when n is even;f(n)=f(3n+1)when n is odd. Write recursive function to compute f(n).

- 0of 0 votes
A program P reads in 500 integers in the range (0,100) representing the scores of 500 students. It then prints the frequency of each score above 50. Implement program P in C language.

- 0of 0 votes
There are four coins a , b , c , d out of which three coins are of equal weight and one coin is heavier. Write a C program to find the heavier coin.

- 0of 0 votes
You are given a string X and integer k (0 <= k < length of X). For each value of k you can look at a sub-string of X starting from index 0 to index k and choose to reverse it. As an example, let X = LMNAP and k = 2. If you reverse the sub-string of X between 0 and 2 you will get NMLAP. Subsequently if choose k = 3 and reverse you will end up with ALMNP.

Given the string X as an input find lexicographically earliest possible string. In the example above, lexicographically ALMNP comes earlier than NMLAP.

Input:

AACAACAABBABACAACBCACCCAAABACABACACCBCCAAABABACBCC

Expected Output: AAAAAAAAAAAAAAAAAAAAAAACCBBBCCBCCCCBCBCCCBCCBBCBCC

Input:

BACBCBCACAACBCBBCCBACCCCAACCBCCAABACAABCAAAABBAABC

Expected Output: AAAAAAAAAAAAAAAAAABCBCBCCCBCBBCCBCCCCCCBCCBCBCBBBC

- 2of 2 votes
Given a undirected graph with weights, return the sum of the weight of each path between two nodes (shortest path between two vertices). Assume there are no cycles.

Example:`Input: A | 1 B 2 / \ 3 C D Output: 18 since A to B has weight 1 A to C has weight 3 A to D has weight 4 B to C has weight 2 B to D has weight 3 C to D has weight 5`

Edit: Thanks, wangchenClark0512, forgot about C to D

Edit2: @Lukas, The question is just the sum of the shortest paths between two vertices. Also, all edges are positive.

Edit3: Assume the graph has no cycles, did not get to the follow-up, but follow-up probably is probably change your algorithm so that is works for cycles

- 4of 4 votes
You are given a graph with no cycles, each node representing different cities and there are stadiums for baseball games in all cities.

Each node contains a value representing the population of the city, and a list of neighbors. (feel free to extend data structure)

Every time there is a baseball game at a city, everyone from all the different cities will go to the city with the baseball game.

Return the maximum traffic between a city and its neighbours when there is a game at that city, for all cities. (Does not have to be sorted)

The total run-time after returning everything should be O(n).

Examples:`Input: 1 2 \ / 5 / \ 4 3 Output: 1 14 2 13 3 12 4 11 5 4 Input: 38 / 8 / 7 / 1 2 \ / \ 5 15 / \ 4 3 Output: 1 82 2 53 3 80 4 79 5 70 7 46 15 68 8 38 38 45`

- 1of 1 vote
Given a length n, return the number of strings of length n that can be made up of the letters 'a', 'b', and 'c', where there can only be a maximum of 1 'b's and can only have up to two consecutive 'c's

Example:

findStrings(3) returns 19

since the possible combinations are: aaa,aab,aac,aba,abc,aca,acb,baa,bac,bca,caa,cab,cac,cba,cbc,acc,bcc,cca,ccb

and the invalid combinations are:

abb,bab,bba,bbb,bbc,bcb,cbb,ccc

- 0of 0 votes
Suppose you have a matrix in the form of a 2 dimensional array. Write a method to read the rows of the matrix alternatively from right to left, left to right so on and return them as a 1 dimensional array.

for eg:

1 2 3

4 5 6

7 8 9

should return 1 2 3 6 5 4 7 8 9

- 3of 3 votes
# take an array and print non over lapping in order pairs. example:

`# [1,2,3,4] => input # output below is in order combination # (1234) # (1)(234) # (1)(23)(4) # (1)(2)(34) # (12)(34) # (12)(3)(4) # (123)(4) # (1)(2)(3)(4)`

- 0of 0 votes
You have given an array of integers. The appearance of integers vary (ie some integers appears twice or once or more than once) How would you determine which integers appeared odd number of times ?

a[] = { 1.1.1, 2,5,10000, 5,7,4,8}

as you can see 1 appeared 3 times, 2 appeared once etc

- 0of 0 votes
what is output for below code and what is purpose of using const type for pointer variable p?

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

char a[10]="HELLO";

char *const p=a;

clrscr();

//puts(p);

printf("%s",p);

*p='n';

//puts(p);

printf("%s",p);

getch();

}

- 0of 0 votes
Int a=10;

Int b=a>15;

Print("%d",b);

a)15

b)10

c)0

d)1

- 0of 0 votes
Virtual memory can be handled by which of the following?

a)demand paging

b)demand segmentation

c)both a and b

- 0of 0 votes
Using which data structures the arthematic expressions can be calculated?

- 0of 0 votes
Find a sub string in a given string and replace it with another string?

- 0of 0 votes
Implement a solution nth_largest( array, n ) that takes in an array of arbitrary size and returns the nth largest element.

`Eg. array = [1, 8, 4, 5, 9, 7, 2, 10, 44, 55, 67] nth_largest( array, 2) = 55 nth_largest( array, 5) = 9`

- 0of 0 votes
Write a program to identify if a given binary tree is balanced or not.

- 0of 0 votes
Write a program to print all permutations of a given string.

- 0of 0 votes
If you have the chapter of a book and you're supposed to build an index such that given a word, you can tell which pages the word occurs on, what data structure can you use? Optimize for space utilization.

- 0of 0 votes
Write a Python program to print numbers from 1 to 100 except for multiples of 3 for which you should print "fuzz" instead, for multiples of 5 you should print 'buzz' instead and for multiples of both 3 and 5, you should print 'fuzzbuzz' instead.

- 0of 0 votes
Implement a function DoIt( o,a ) such that the following code:

`Object o = SomeClass() O.first = 'fizz' O.second = 'buzz' print DoIt( o, 'first) print DoIt(o, 'second')`

prints

fizz

buzz

- 0of 0 votes
Write a iterative Python function to print the factorial of a number n (ie, returns n!).

- 0of 0 votes
Write a recursive Python function to print the factorial of a number n (ie, returns n!).