Collection of coding questions appearing in online assessment of Indeed during campus placements at IIT/NITs, and other top engineering colleges in India.
- Almost Sorted [IIT-BHU'22]
- Shared Interest [IIT-BHU'22]
An array of integers is
Remove
Complete the function minDeletions
.
minDeletions
has the following parameter(s):
-
$int \ \ arr[n]$ : an unsorted array of integers
-
$int$ : the minimum number of items that must be deleted to create an almost sorted array
$1 \leq n \leq 10^5$ $1 \leq arr[i] \leq 10^9$
Show
int minDeletions(vector<int> arr) {
int N = arr.size();
vector<int> v = {0};
for (int i = 0, x; i < N; i++) {
x = arr[i];
int j = lower_bound(v.begin(), v.end(), x) - v.begin();
if (j == v.size()) v.push_back(x);
else v[j] = x;
}
int ans = v.size() - 1;
int K = N - (ans + (ans != N));
return K;
}
Given a graph of friends who have different interests, determine which groups of friends have the most interests in common. Then use a little math to determine a value to return.
The graph will be represetned as a series of nodes numbered consecutively from
From | To | Weight |
---|---|---|
The graph shows the following connections:
Weight (Interest) |
Connectons |
---|---|
- Node pair
$(2, 4)$ shares only$1$ interest$(4)$ and node pair$(1, 3)$ shares$1$ intereste$(3)$ . - Node pair
$(1, 2)$ shares$2$ interests (interests$2$ and$3$ ) and node pair$(2, 3)$ shares also$2$ interests (interest$1$ and$3$ ). So, the maximum number of shared interests is$2$ . - Multiply the
$friends \textunderscore nodes$ of the resulting node pairs:$1 \times 2 = 2$ and$2 \times 3 = 6$ - The maximal product is
$6$ .
Comeplete the function maxShared
.
maxShared
has the following parameter(s):
-
$int \ \ friends \textunderscore nodes$ : number of nodes -
$int \ \ friends \textunderscore from[friends \textunderscore edges]$ : the first part of node pairs -
$int \ \ friends \textunderscore to[friends \textunderscore edges]$ : the other part of node pairs -
$int \ \ friends \textunderscore weight[friends \textunderscore edges]$ : the interests of node pairs
-
$int$ : maximal interger product of all node pairs sharing the most interests.
$2 \leq friends \textunderscore nodes \leq 100$ -
$1 \leq friends \textunderscore edges \leq$ $min(200, \frac{friends \textunderscore nodes \ \times \ (friends \textunderscore nodes - 1)}{2})$ $1 \leq friends \textunderscore weight[i] \leq 100$ -
$1 \leq friends \textunderscore from[i]$ ,$friends \textunderscore to[i] \leq friends \textunderscore nodes$ $1 \leq friends \textunderscore weight[i] \leq friends \textunderscore edges$ $friends \textunderscore from[i] \neq friends \textunderscore to[i]$ - Each pair of friends can be connected by zero or more interests.