Collection of coding questions appearing in online assessment of InMobi during campus placements at IIT/NITs, and other top engineering colleges in India.
- Broken Chain [IIT-BHU'22]
- Reportee Count [IIT-BHU'22]
- Connected Flights [IIT-BHU'22]
There is a large broken chain (think of Ship Anchor Chain) with
- Picky any two pieces and join those.
- Repeat this process until all pieces are joined.
Each join operation requires some cost (labour cost, welding cost etc.). Cost of each join operation is equal to sum of the Weights
- Value of
$N$ in$1st$ line - Comma and space separted
$N$ integers in$2nd$ line, which denote individual weights of$N$ pieces.
$1 \leq N \leq 10^5$ $1 \leq W \leq 10^5$
- Value of minimum total cost
4
8, 2, 3, 4
31
In aboe sample, broken chain has 4 pieces with given weights. Two pieces are joined at a time, for example if
In a company containing
Find the total number of reportees (
- First line contains an integer denoting total number of employees
$N$ - Next
$N - 1$ lines contain two space-separated integers$n_1$ and$n_2$ where$n_2$ is manager of$n_1$
$2 \leq N \leq 10^5$
- Print
$N$ integers separated by space where$1st$ integer is total number of reportees of employee with$id = 1$ ,$2nd$ value is total number of reportees of employee with$id = 2$ and so on.
5
2 1
3 2
4 1
5 3
4 2 1 0 0
Manager of Employee
Manager of Employee
Manager of Employee
Manager of Employee
This is how the org structure looks like for this example:
There are
You are given a list of
Now given
Return the cheapest route from
If there is no such route, return
- First line contains total number of cities
$n$ - Second line contains total number of flights
$m$ - Third line contains source city
$src$ - Fourth line contains destination city
$dst$ - Fifth line contains max number of stops allowed
$k$
$1 \leq n \leq 100$ $1 \leq src \leq n$ $1 \leq dst \leq n$ $src \neq dest$ $1 \leq k \lt n$ -
$Note:$ There is only$1$ direct flight between any$2$ cities.
- Return one integer which denotes the total cost of the cheapest route.
6
8
0
3
1
0 1 10
0 2 10
0 3 15
0 4 2
1 3 20
2 3 50
4 5 2
5 3 2
15
The flight graph for this example looks like this:
We have to find the cheapest combination of flights froms source =