Mock Test 1
Mock Test 1
Mock Test 1
Test Summary
No. of Sections: 2
No. of Questions: 3
Total Duration: 90 min
Section 1 - Coding
Section Summary
No. of Questions: 2
Duration: 60 min
Additional Instructions:
None
Q1.
Problem Statement
There are N people standing in a circle waiting to be executed. The counting out begins at some
point in the circle and proceeds around the circle in a fixed direction. In each step, a certain
number of people are skipped and the next person is executed. The elimination proceeds around
the circle (which is becoming smaller and smaller as the executed people are removed), until
only the last person remains, who is given freedom.
Given the total number of persons N and a number k which indicates that k-1 persons are
skipped and the kth person is killed in a circle. The task is to choose the person in the initial
circle that survives.
Example 1
Input:
N = 5 and k = 2
Output:
3
Explanation:
Firstly, the person at position 2 is killed, then the person at position 4 is killed, then the person at
position 1 is killed.
Finally, the person at position 5 is killed. So the person at position 3 survives.
Example 2
Input:
N = 7 and k = 3
Output: 4
Explanation:
The persons at positions 3, 6, 2, 7, 5, and 1 are killed in order, and the person at position 4
survives.
Input Format
The input consists of two integers, representing the value of n, followed by the value of k,
separated by space.
Output Format
The output prints the person in the initial circle that survives.
Q2.
Problem Statement
Example:
Input:
artyebui
2
Output:
6
Explanation: The longest substring with only two vowels is "rtyebu" and its length is 6.
Input Format
The first line contains the string s.
The second line contains the integer k.
Output Format
The output displays a single integer representing the length of the longest substring that contains
exactly k distinct vowels. If no such substring exists, output -1.
Inversion Count: For an array, the inversion count indicates how far (or close) the array is from
being sorted. If the array is already sorted, then the inversion count is 0. If an array is sorted in
reverse order, then the inversion count is the maximum.
Formally, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j.
Example 1:
Input:
N = 5, arr[] = {2, 4, 1, 3, 5}
Output:
3
Explanation:
Sequence 2, 4, 1, 3, and 5 has three inversions (2, 1), (4, 1), and (4, 3).
Example 2:
Input:
N=5
arr[] = {2, 3, 4, 5, 6}
Output:
0
Explanation:
As the sequence is already sorted, there is no inversion count.
Example 3:
Input:
N = 3, arr[] = {10, 10, 10}
Output:
0
Explanation:
As all the elements of the array are the same, there is no inversion count.
Input Format
The first line of the input is the size of the array.
The second line of the input is the list of space-separated integer values.
Output Format
The output is the inversion count in the array.
Constraints
1 ≤ N ≤ 5*105
1 ≤ arr[i] ≤ 1018
Sample Input Sample Output
5
2 4 1 3 5 3
Sample Input Sample Output
5
2 3 4 5 6 0
Sample Input Sample Output
3
10 10 10 0
Time Limit: - ms Memory Limit: - kb Code Size: - kb
Q1Test Case
Input Output
10 4 5
Weightage – 10
Input Output
16 1 16
Weightage – 10
Input Output
18 4 9
Weightage – 15
Input Output
22 7 17
Weightage – 25
Input Output
18 3 14
Weightage – 25
Input Output
10 5 3
Weightage – 15
Solution
#include <stdio.h>
int josephus(int n, int k)
{
if (n == 1)
return 1;
else
return (josephus(n - 1, k) + k-1) % n + 1;
}
int main()
{
int n,k;
scanf("%d%d",&n,&k);
printf("%d",josephus(n, k));
return 0;
}
Q2Test Case
Input Output
uhtionbgfd
2 9
Weightage – 15
Input Output
redtuni
1 4
Weightage – 10
Input Output
mkihgtd
1 7
Weightage – 10
Input Output
americabhu
2 6
Weightage – 15
Input Output
nihbdtctwwbt
2 -1
Weightage – 25
Input Output
tHeracEBetwEEnthinyf
2 11
Weightage – 25
Solution
#include <bits/stdc++.h>
using namespace std;
// Initialize result to be
// negative
int result = -1;
for (int i = 0, j = -1; i < n; ++i) {
int x = s[i];
if (isVowel(x)) {
if (++c[x] == 1) {
while (k < 0) {
x = s[++j];
if (isVowel(x)) {
if (--c[x] == 0) {
++k;
}
}
}
if (k == 0)
result = max(result, i - j);
}
return result;
}
// Driver code
int main()
{
string s;
int k;
getline(cin, s);
cin >> k;
return 0;
}
Section 2 - Additional Coding
Q1Test Case
Input Output
10
1 5 4 7 85 6 3 2 1 5 4 24
Weightage – 10
Input Output
15
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0
Weightage – 30
Input Output
15
23 56 98 75 14 27 65 45 89 20 56 47 55 66 33 52
Weightage – 30
Input Output
10
66 55 44 77 88 99 11 22 33 89 22
Weightage – 20
Input Output
5
11 15 65 87 25 2
Weightage – 10
Solution
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main
{
public static void main (String[] args)
{
Scanner sc = new Scanner(System.in);
long n = sc.nextLong();
long arr[] = new long[(int)n];