Collection of coding questions appearing in online assessment of AiDash during campus placements at IIT/NITs, and other top engineering colleges in India.
- Jump To The Flag [IIT-BHU'22, IIT-R'22]
- Whole Minute Dilemma [IIT-BHU'22, IIT-G'22]
- Longest Increasing Subsequence [IIT-BHU'22]
A climber is trying to reach a flag that is some height above the ground. In the attempt to reach the flag, the climber can make any number of jumps up the rock wall where the flag is mounted. Movements can only be made up the wall, and the climber must end at exactly the height of the flag.
There are
- A jump of height
$1$ . - A jump of height
$bigjump$ .
Determine the minimum number of jumps it will take the climber to reach the flag's exact height.
$flagHeight = 8$ $bigjump = 3$
The climber starts at height
Complete the function jumps
.
jumps
has the following parameter(s):
-
$int \ \ flagHeight$ : an integer, the flag height -
$int \ \ bigjump$ : an integer, the height of the second type of jump
-
$int$ : an integer, the minimum number of jumps necessary
$1 \leq bigjump, flagHeight \leq 10^9$
Sample Input | Sample Output |
3
1 |
3 |
Show
int jumps(int flagHeight, int bigJump) {
return flagHeight / bigJump + flagHeight % bigJump;
}
A music player allows users to choose songs to play, but only in pairs and only pairs of songs with durations that add up to a multiple of
One pair of songs can be chosen whose combined duration is a multiple of a whole minute
Complete the function playlist
.
playlist
has the following parameter(s):
-
$int \ \ songs[n]$ : array of integers representing song durations in seconds
-
$int$ : the number of songs pairs that add up to a multiple of a minute
$1 \leq n \leq 10^5$ -
$1 \leq songs[i] \leq 1000$ , where$0 \leq i \lt n$
Sample Input | Sample Output |
4
10 50 90 30 |
2 |
The first and second songs pair to
Show
long playlist(vector<int> songs) {
int N = songs.size(), M = 60;
vector<int> A(65);
long ans = 0;
for (int i = 0; i < N; i++) {
int x = (M - songs[i] % M) % M;
ans += A[x];
A[songs[i] % M]++;
}
return ans;
}
A sub-sequence is a sequence that can be created by deleting zero or more elements from the original sequence while maintaining order.
A sequence
You will be given an array of integers and must determine the length of the longest increasing subsequence.
For example, your array
Complete the function findLIS
. The function must return the length of the longest increasing subsequence that can be created from the array.
findLIS
has the following parameter(s):
-
$s[s[0], \ ..., \ s[n - 1]]$ : an array of integers
$1 \leq n \leq 1000$ $1 \leq s[i] \leq 10^6$
Sample Input | Sample Output |
3
1 4 3 |
2 |
Inputs are
The longest increasing sub-sequence has
Show
int findLIS(vector<int> S) {
int N = S.size();
vector<int> v = {0};
for (auto x: S) {
int j = lower_bound(v.begin(), v.end(), x) - v.begin();
if (j == v.size()) v.push_back(x);
else v[j] = x;
}
return (int) v.size() - 1;
}