Mock Test 3
Mock Test 3
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:
Given a base b, any number n < b is trivially a Niven number. We will ignore this case.
Given a base b, and a positive integer T, find the lowest number L such that L, L+1,
..., L+T-1 are all Niven numbers but neither L-1 nor L+T are Niven numbers.
Input Format
The input consists of two integers b and t separated by a space.
b: The base to which the numbers will be converted.
t: The number of consecutive numbers in the given base which satisfy the condition.
Output Format
The output displays a single integer L such that L, L+1, ..., L+T-1 are all Niven
numbers but neither L-1 nor L+T are Niven numbers.
You are given an integer array prices where prices[i] is the price of a given stock on
the ith day, and an integer k.
Find the maximum profit you can achieve. You may complete at most k transactions:
i.e. you may buy at most k times and sell at most k times.
Note: You may not engage in multiple transactions simultaneously (i.e., you must sell
the stock before you buy again).
Example 1
Input:
2
3
241
Output:
2
Explanation:
Buy on day 1 (price = 2) and sell on day 2 (price = 4), profit = 4-2 = 2.
Example 2
Input:
2
6
326503
Output:
7
Explanation:
Buy on day 2 (price = 2) and sell on day 3 (price = 6), profit = 6-2 = 4. Then buy on day
5 (price = 0) and sell on day 6 (price = 3), profit = 3-0 = 3.
Input Format
The first line contains an integer k representing the maximum number of transactions
allowed.
The second line contains an integer n representing the number of days.
The third line contains n space-separated integers representing the prices of the stock
on each day.
Output Format
The output displays an integer representing the maximum profit achievable with at
most k transactions.
Q1Test Case
Input
5 5
Output
44
Weightage – 10
Input
5 3
Output
200
Weightage – 15
Input
7 5
Output
66
Weightage – 10
Input
8 4
Output
11020
Weightage – 25
Input
8 3
Output
4224
Weightage – 15
Input
10 6
Output
12751220
Weightage – 25
Sample Input
10 4
Sample Output
510
Solution
#include<stdio.h>
#include<string.h>
while(no > 0)
{
int quot = no / base;
int rem = no % base;
store[index++] = rem;
no = quot;
}
int converted_no = 0, i;
for(i = index - 1; i >= 0; i--)
{
converted_no = converted_no * 10 + store[i];
}
return converted_no;
}
int compute_sum_of_digits(int n)
{
int sod = 0;
while(n > 0)
{
sod = sod + n % 10;
n = n / 10;
}
return sod;
}
int main() {
int b, t;
scanf("%d %d", &b, &t);
int i, count = 0;
for(i = b; ; i++)
{
int tmp = convert_to_base(i, b);
int sod = compute_sum_of_digits(tmp);
if(i % sod == 0)
{
count++;
}
else
{
if(count == t)
{
break;
}
count = 0;
}
}
Q2Test Case
Input
10
Output
89
Weightage – 10
Input
20
Output
10946
Weightage – 10
Input
29
Output
832040
Weightage – 15
Input
36
Output
24157817
Weightage – 25
Input
25
Output
121393
Weightage – 15
Input
30
Output
1346269
Weightage – 25
Sample Input
45
Sample Output
1836311903
Solution
#include <stdio.h>
results_cache[curr_step] = total_ways;
return total_ways;
}
Q1Test Case
Input
1
5
90 80 70 60 50
Output
0
Weightage – 10
Input
3
7
100 30 15 10 8 25 80
Output
72
Weightage – 15
Input
3
8
12 14 17 10 14 13 12 15
Output
12
Weightage – 25
Input
3
5
56 77 89 34 27
Output
33
Weightage – 15
Input
4
7
76 12 34 90 15 19 26
Output
89
Weightage – 25 Input
2
3
10 20 30
Output
20
Weightage – 10 Sample Input
2
3
2 4 1
Sample Output
2
Sample Input
2
6
3 2 6 5 0 3
Sample Output
7
Solution
#include <climits>
#include <iostream>
using namespace std;
int main()
{
int k;
cin >> k;
int n;
cin >> n;
int price[n];
for (int i = 0; i < n; ++i) {
cin >> price[i];
}
return 0;
}