## Dev Lead Interview Questions

- 0of 0 votes
Design and implement a multi-threaded application that finds the occurrence(s) of a string in a text file of 100GB. It should return the line-number(s) in which the match(es) is/are found.

Need not worry about the system constraints in spawning and running threads. There is a 32 core CPU with immense power. Huge amount of RAM.

The result should be returned in few sec.

- 0of 0 votes
As an online retailer, design a price scraper service that determines the best prices at which products should be sold on the website.

Should be able to check prices on competitor websites like Amazon, ebay etc. and suggest the best price in real time. Should be scaled to support price determination of 1 million products from 50k different sources.

- 0of 0 votes
Design a system for implementation of stock market.

Buyer and seller case. stock server will receive buy request and sell request. A sell can be successful when it matches the quantity and price for same stock.

There will be many request for buyer and seller . Need to select the appropriate one.

Which data structure will be used ? how to handle concurrency issue?class diagram?

- -2of 2 votes
Write code to traverse a NxM matrix in a zig-zag fashion

- -1of 1 vote
Given a random string (reasonable length L), knowing all possible font sizes (e.g. font Fn has min_width, max_width, min_height, max_height), knowing fixed screen size, find the max font size that can display said string

- 0of 0 votes
Implement a2i - what are the edge cases you can think of? Signed integer only, subject to OS dependent MIN, MAX values

- 0of 0 votes
We are given a book with N number of pages and two words. Find the distance(in pages) between the first occurrence of first word and first occurrence of second word. For Example, you are given the book "Thinking in C++" and two words 1. "Inheritance" whose first occurrence is in page 220 and 2. "Polymorphism" whose first occurrence is in page 350, the result would be 130. You can take your decision to choose how the data structure of the book would be.

- 0of 0 votes
Hi Implemented this sample code for N-ary postOrder Traversal.

Now i want to throw error statement id the parent node is dependent on child.

Can some one help

package dependencyAlgorithm;

import java.util.*;

public class Dependency

{

class MainRule

{

String ruleName;

ArrayList<MainRule> subrule;

public MainRule(String name)

{

this.ruleName=name;

subrule=new ArrayList<>();

}

}

public static void postOrder(MainRule rootRule)

{

Stack<List<MainRule>> stack = new Stack<>();

MainRule rule = rootRule;

List<MainRule> list = null;

while (true)

{

if(rule != null)

{

list = rule.subrule;

for(int i=0;i<list.size();i++)

{

if(rule.ruleName == list.get(i).ruleName)

break;

}

rule = null;

if(list!=null && list.size()>0)

{

//push the list in the stack (do not modify original tree structure).

stack.push(new ArrayList<>(list));

//get first item from this list

rule = stack.peek().get(0);

System.out.print("\n1 ListSize: "+list.size());

}

}

else if (!stack.isEmpty())

{

System.out.print("\n2 \n");

list = stack.pop();

System.out.print("\n2 ListSize: "+list.size());

rule = list.remove(0); //shift left

System.out.print("\n2.1 ListSize: "+list.size());

System.out.print("\n"+rule.ruleName+" ");

rule = null;

if(list.size()>0)

{

System.out.print("\n3 ListSize "+list.size());

stack.push(list); //push back remaining list into stack

rule = stack.peek().get(0); //prepare for next iteration

}

}

else

break;

}

System.out.println(rootRule.ruleName);

}

/*

Fml001

/ | \

/ | \

/ | \

Fml002 C001_Base Tot001

/ / | \

/ / | \

Fml003 Fml004 R001_Base R001_TxPat

/

/

Tot002

\

\

C001_TxPat

*/

public void createBinaryTree()

{

MainRule rootRule;

MainRule Fml001 =new MainRule("Fml001");

MainRule Fml002=new MainRule("Fml002");

MainRule Fml003=new MainRule("Fml003");

MainRule Fml004=new MainRule("Fml004");

MainRule C001_Base=new MainRule("C001_Base");

MainRule R001_Base=new MainRule("R001_Base");

MainRule Tot001=new MainRule("Tot001");

MainRule Tot002 =new MainRule("Tot002");

MainRule R001_TxPat =new MainRule("R001_TxPat");

MainRule C001_TxPat =new MainRule("C001_TxPat");

rootRule=Fml001;

rootRule.subrule.add(Fml002);

rootRule.subrule.add(C001_Base);

rootRule.subrule.add(Tot001);

Fml002.subrule.add(Fml003);

C001_Base.subrule.add(Fml004);

C001_Base.subrule.add(R001_Base);

C001_Base.subrule.add(R001_TxPat);

R001_Base.subrule.add(Tot002);

Tot002.subrule.add(C001_TxPat);

postOrder(rootRule);

}

public static void main(String[] args)

{

Dependency dependency=new Dependency();

// Creating a tree structure

System.out.println("Path Traversed:");

dependency.createBinaryTree();

}

}

- 0of 0 votes
you have millions of records in DB. How could you display those records efficiently as a paginated view. Which UI technology would you use and why? how will you design the back end?

- 0of 0 votes
You have a big .csv file (say the size is 3GB). How efficiently you can process it and put the records in database?

- 0of 0 votes
is there a way to make the bean not initialize when spring application context coming up

- -2of 2 votes
Input

2 5

2000

5000

Output

1000

Question: A real estate company plans to open relief distribution in few cities of a state.

The input in the first Line N(number of cities...2 as per example)

and M(Number of distribution center...5 as per example).

The next lines have the number of population in N(2) cities. (2000 and 5000) as per example.

Only people from a specific city can go to the distribution center of that city.

WAP to find the number of max people those can be accommodated in a distribution center.

The answer is 1000 in this case. As there are 7 distribution center.

First City having 2000 population will have 2 distribution center and second city having 5000 population will have 5 centers.

Therefore Max person that can be accommodated in a center is 1000.

- 0of 0 votes
Generic Question: You have a list of items that's nearly sorted. What algorithm would you use to completely sort it? Even though it's already sorted, the least element could be at the other end ...eg: 4,5,6,7,8,9,10,11,1

She then said that what would be the approach if the data was not like that, as in , not so extreme.

- 0of 0 votes
how to find all paths of a graph?

hi ,

i have a directed graph as an input and i want to find in that graph subGraphs that fit to some path

for example : i have the following graph 1[E] ->2[E] ->3[M]->4[E]->5[M]->6[M]->7[E]->8[M] .and i have the path E->M->E

then the program output should be the subGraph 2->3->4

note that the solution should be implemented as ADJ Matrix

the Graph is directed DAG

the program should be with C language

- 0of 0 votes
there are N employee sitting in consecutive cubicles , we have to send a few of them to onsite , but each time we send one employee onsite , his cubicle becomes empty , now the other employees from both side of that empty cubicle stops working until they are given a gift .

the gifts are given in both sides of the empty cubicle until we reach the end or found another cubicle ,

Input – number of cubicle , and index numbers of people to be sent

output- min number of gifts needed

- 5of 5 votes
A plumber working for a company as a contractor. His job is attend services and submit the bill to get his salary on basis of daily work including his service charge 500 rupees. For a typical plumbing work he need pipes with different lengths. But in market he will get new pipe with standard size 100m of cost 100 rupees. (no small or large sized pipes available) Now , he need 10 , 40 , 60, 70 lengths of pipes for a jobwork.

Generally company gives him (4 pipes * 100 rupees) + 500rupees as service charge = 900 rupees.

but plumber bought only 2 pipes cut as follows and get his job done...

1st pipe => 40+60

2nd pipe => 10+70 + extra left(20)

By buying only 2 pipes he get his job done. remaining 2 pipes money saved.

write an efficient algorithm to calculate minimum number of standard size pipes required for given number of different pipes lengths:

Input:

N => total pipes for jobwork

arr[N] => lengths of pipes. (for simplicity, pipe size will be either smaller or equal to standard size)

outpud:

minimum statdard sized(100m) pipes required

constraint: you can only cut them can not join them back as follows

say he need 10 95 95,

with two pipes 100 100 = > 95+5 95+5 => 95 95 (5+5)// this is not accepted

EX:

Input:

5

20 30 50 60 80

output:

3

Input:

5

10 10 10 15 20 35 55 60 70 75 75 80

output:

6

- 1of 1 vote
Print all subset of a given set which sums up to ZERO

{8,3,5,1,-4,-8}

so ans will be : {8,-8}

{3,5,-8}

{3,1,-4}

size of set can be upto 50 but elemet of set can be as big as 18 digit number

- 0of 0 votes
Hi ,

Given a set of number eg {5,3,1,8, -8,-4}

Print all subset which will sum up to ZERO

for eg {3,1,-4} {5,3,-8}, {8,-8}

Note : size of subset can be max 100 and element can be very big like 13 or 14 digit number

- 0of 0 votes
I have used my personal google API key here, you can use that or generate your own.

The response id JSON:

{

"destination_addresses" : [ "Sector 15, Faridabad, Haryana, India" ],

"origin_addresses" : [ "GBN School, Sector 21D, Faridabad, Haryana 121001, India" ],

"rows" : [

{

"elements" : [

{

"distance" : {

"text" : "6.1 km",

"value" : 6054

},

"duration" : {

"text" : "12 mins",

"value" : 716

},

"status" : "OK"

}

]

}

],

"status" : "OK"

}

Base Algorithm or the rule engine for scheduling:

For the examples, let us assume pincode 121001, with 3 cabs cab1, cab2 & cab3.

The time slots are:

9:00 am to 10:30 am, 10:30 am to 12:00 pm, 12:00 pm to 1:30 pm, 2:30 pm to 4:00 pm, 4:00 pm to 5:30 pm and 5:30 pm to 7:00 pm

Non-real time scheduling

For an appointment of any time slot, say 4:00 pm to 5:30 pm, check the cabs allotted for adjacent slots, 2:30 pm to 4:00 pm and 5:30 pm to 7:00 pm for this example.

1) If no cabs are allotted for adjacent slots, then assign any random cab, say cab1.

2) Else, say cab2 is allotted to slot 2:30 pm to 4:00 pm and cab3 to 4:00 pm and 5:30 pm. Using google distance matrix api (referred to as gdm api from now on), find which cab is within x kms (x should be configurable, e.g 5 kms would be a good start) of the new appointment.

2.1) If one of the cabs is within x kms, assign it to this time slot.

2.2) If both cabs are within x kms, assign the one that is closer. If the difference is imperceptible, assign one randomly.

2.3) If both cabs are more than x kms, assign it to cab1

2.4) If cab1 was also allotted one of the adjacent time slots, then assign the nearest cab to this time slot. If the difference is imperceptible, assign one randomly.

Real time scheduling

This is applicable for appointments for the same day.

The same algorithm can be used, but use time to travel from the gdm api, instead of distance, since it accounts for traffic.

Feel free to discuss details or suggest changes in the rule engine.

- 0of 0 votes
A batch of time intervals like {2/3-2/20, 2,6-3/5}. need to split the intervals to{2/3-2/6, 2/7-2/20, 2/21-3/5}. Solve it with minimum time complexity. How to do it?

- 0of 0 votes
A seller sells lot of products in his store and people place orders,just like any other store. Each item has a different weight and price.

And each order can be a combination of different number of items with random quantity. Now each of these orders areto be put into different packages and sent to the courier company for delivery.

But there are certain rules while splitting items into packages, they are as below:

1. If the cost of all the items in an order is more than $1000, split those items into multiple

packages, otherwise one package would be enough.

2. If the items in the same order are split into multiple packages, then the weight of the

packages should be equally distributed over the packages with consideration of optimum

courier charges.

3. While splitting, NO PACKAGE can have a total price above $1000

- 0of 0 votes
Given two string you need to tell whether edit distance between two string is 1 or not.

- 0of 0 votes
Two sorted array of integer are given, you need to find nth rank element from combine array.

- 0of 0 votes
There is a set of n bolts and n nuts given. You have only API that tells whether given nut is smaller or larger then for a bolt no any other relative number. You need to match all nuts and bolts in O(nlogn).

- 0of 0 votes
Given an abstract class A having a function sumBill(int a, int b). Now assume that you have 3 or 4 class extending class A and implementing their version of sumBill. And in various locations in the code you are making calls to sumBill with integer parameters.

Later on it is identified that the parameters need to be of type double rather than int. So now one has to go refactor all the places which make a call to sumBill to pass parameters of double data type.

So the question is what could the developer had done better to avoid such a problem in the first place.

Its a design pattern question.

- 0of 0 votes
class template vs template class?

c++ specific properties?

struct vs class?

encapsulation vs abstraction?

Design a holder - bulbs(LED,Normal,Tube light) - uml relation ship?

multiple inheritance, multiple level inheritance-CTOR and DTOR order for base classes ?

why use templates?

what is abstract class?

unit testing tools used?

smart poiner vs dangling pointer

why we take "Base& obj" as input in Base Copy CTOR function, in Base(Base& obj){}, why not "Base obj".

shallow copy vs Deep copy.

- 0of 0 votes
Given a set of road segments:

class Seg { int ID; int NextID; }

Implement a method that finds the longest connected stretch for a random collection of segments:

Seg[] FindLongest(Seg[] segs);

Assume that each NextID have a corresponding object with ID == NextID in the input. (-1 or any negative ID) indicates no link. No other assumptions about input should be made

- 1of 1 vote
Two dices are tossed. Once die is regular and the other is biased with probabilities P(1) = P(6) = 1/6, P(2) = P(4) = 0, P(3)= P(5) = 1/3.

Determine the probabilities of obtaining the sum 4.

- 0of 0 votes
Find the permutation of a given string using dynamic programming . Try to do with the best possible time complexity and space complexity .

- 0of 0 votes
Given a Tree (binary and unbalanced)

Find all the nodes in that tree which are 'n' levels up the leaf node...

Eg:

A->root

A.left=B

A.right=C

B.left=D

B.right=E

C.right=F

D.right=G

then

if 'n' as described in the above problem statement, is say n=2

then

answer should be :

B(2 nodes up from G), A(2 nodes up from E & F)

hence ans is B,A

My Algo was;

1)Perform a DFS (left,middle, right)

2) when leaf node is encountered.. just move the stack pointer (without poping or jsut coy the stack of DFS to another stack and perform a real time pop operation) by 'n' times and then just print the node which it encounters.

code:

int n=2;

Stack treeStack = new Stack();

function find(){

treeStack .push(rootnode);

performDFS();

}

function performDFS(){

if(currnetnode.left==null && currentnode.right==null){

// this is a leaf node.

Stack tmpStack=copyStack(treeStack);

// hard coded logic(two pop operations) without using a loop since i am usnig n=2 in //this example

tmpStack.pop(); // pop 1st element

element = tmpStack.pop(); // print the 2nd element

print(element);

}

if(currnetnode.left!=null)

treestack.push(currentnode.left);

if(currnetnode.right!=null)

tree.stack.push(currentnode.right);

}