0% found this document useful (0 votes)
3 views9 pages

PracticeProblems EfficientCoding

The document contains multiple problem statements related to programming challenges. Each problem involves different scenarios such as counting unique medicines, equalizing DNA sequences, managing package weights, calculating team scores based on lap timings, determining maximum skips in a playlist, and accessing specific tools in a multilevel toolbox. Each problem includes input formats, constraints, and sample outputs to guide the implementation of solutions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

PracticeProblems EfficientCoding

The document contains multiple problem statements related to programming challenges. Each problem involves different scenarios such as counting unique medicines, equalizing DNA sequences, managing package weights, calculating team scores based on lap timings, determining maximum skips in a playlist, and accessing specific tools in a multilevel toolbox. Each problem includes input formats, constraints, and sample outputs to guide the implementation of solutions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Problem Statement:
John is a pharmacist. He receives a new shipment of medicines, consisting of P
medicines in which there can be multiple batches of one or more medicines.

For unique identification, each medicine is assigned an integer called unique


identity (positive or negative integer) to it.

Determine the number of unique medicines, the frequency of each type of


medicine (to be displayed in ascending order), and the average. The average can
be calculated by dividing the total number of medicines by the total number of
unique medicines.

Note: If the average is a decimal number, display the ceil value of it as an integer.
A ceil() value means rounding up the decimal value to the nearest integer.

Input Format: The first line contains a single integer P, denoting the number of
medicines. The next line contains P space-separated integers of array C where
each integer denotes the unique identity of medicines.
Sample Input:
7 -- denotes P
-5 6 -5 6 -15 6 6 – denotes elements of array C

Constraints: 1<=P<=70 -300<=unique identity<=300


Output Format: In the first line, the output should display an integer Q denoting
the unique number of medicines. The next Q lines contain the frequencies of each
medicine in ascending order i.e smallest frequency should be displayed on the
first line and the largest frequency on the Qth line. The last line of the output
should display the average.
Sample Output:
3
1
2
4
2
Explanation: Unique medicines are 3 with UID -5 , 6, -15, The frequency of
medicines in ascending order with UID -15 is 1, -5 is 2, and 6 is 4. And the average
is 2.33. Here we take the ceil value of the average as 2. Hence, the output is. 3 1 2
42

Skeleton Code:

internal class Program


{
static void Main(string[] args)
{
int N = [Link]([Link]().Trim());
int[] A = new int[N];
string[] S = [Link]().Trim().Split(" ");
for (int i = 0; i < N; i++)
{
A[i] = [Link](S[i]);
}
var hmap = new Dictionary<int, int>();
for (int i = 0; i < N; i++)
{
if ([Link](A[i]))
{
hmap[A[i]]++;
}
else
{
hmap[A[i]] = 1;
}
}

//OUTPUT [uncomment & modify if required]


[Link](FrequencyAverage(N, A, hmap));

public static int FrequencyAverage(int N, int[] A, Dictionary<int, int> hmap)


{
//this is default OUTPUT. You can change it.
int result = -404;

//write your Logic here:

return result;
}
}
2.

Problem Statement:
Given are two DNA sequences, S and T, of equal length. Two DNA sequences are
said to be equal if the number of counts of purines (adenine (A) and guanine (G))
and pyrimidines (cytosine (C) and thymine (T)) of the first sequence, S, is equal to
the number of counts of purines and pyrimidines of the second sequence, T. If it's
already equal, you need not do any modification. In one operation, you can
change a purine to a pyrimidine or vice versa in the second sequence only.

Find the minimum number of operations required to change some characters of


the second sequence T to make it equal.
Note: Each character of both sequences will be a lowercase English letter.
Function Description: In the provided code snippet, implement the provided
EqualDNASequences(...) method to find the minimum number of operations
required to change some characters of the second sequence to make it equal.

Input Format: The first line contains a string, denoting the first sequence S. The
second line contains a string, denoting the second sequence T.
Sample Input:
agct - denotes S
tcga - denotes T
Constraints: 1 <= |S| <= 1000000
Output Format: The output contains a single integer denoting the minimum
number of operations required to change some characters of the second
sequence T to make it equal.
Sample Output: 2
Explanation:
● Given sequence S is "agct" and T is "tcga". So the number of purines in S is
2, and pyrimidines in S is
● And the number of purines in T is 1, and pyrimidines in T is 3.
● So we must change two pyrimidines to purines in T so that the number of
purines will become 2 and pyrimidines will become 2.
● Finally, both sequences will become equal. Hence, the output is 2.

Skeleton code:
internal class Program
{
static void Main(string[] args)
{
// INPUT [uncomment & modify if required]
string P = [Link]();
string Q = [Link]();

[Link](EqualString(P, Q));
}

public static int EqualString(string P, string Q)


{
//this is default OUTPUT. You can change it.
int result = -404;

//write your Logic here:


return result;
}
}

3. Problem Statement:

You received a lot of packages last year, but you are yet to open them. You decide
to open all of them but discover that they are all messed up in a storage room.
You decide to stack the packages by arranging them one by one and adding them
at the top of the stack. During the process, whenever you want to open a
package, you open the package with the lowest weight and then discard the
package after opening. To get the package with the lowest weight, you have to
remove all the packages above it and put them back in the messy storage room.

Find the number of packages you must remove, for picking the package with the
minimum weight.
Note: No two people have the same name.
Input Format: The first line contains an integer N denoting the number of actions
you perform. Each of the N lines start with an integer. If the number is -1, it
means you want to open a package. Otherwise, the integer is the weight of the
package followed by the name of the person who sent the package.
Sample Input:
6
9 Harsh
6 Manthan
8 Mayank
-1
3 Vipin
-1
Constraints: 1≤ N ≤ 10000
1<= Weight <=1000
Output Format: For each -1 in the input, the output contains a single line
containing the number of packages you must remove, followed by the name of
the person whose package you should pick.
Sample Output:
1 Manthan
0 Vipin
Explanation: In the first step, you add a package from Harsh of 9 kg in the stack.
On the second step, you add a package from Manthan of 6 kg in the stack. On the
third step, adds a package from Mayank of 8 kg onto the stack. On the fourth
step, you decide to open a package so you select Manthan’s package with the
minimum weight and remove Mayank's package from the top to reach Manthan’s
package, hence we print 1 Manthan. On the fifth step, 3 kg package from vipin is
added to the stack. On the sixth step, you again decide to open a package so you
select Vipin's package with 3 kg and as it is at the top of the stack currently, no
package is removed. Hence, we print 0 Vipin.

4. Problem Statement:
A team of rad Sliding Window participates in a long race event.
Given a stack with the lap timings of N drivers (driver finishing last at the top), a
team score is
calculated as the number of drivers passing a lap before time T.
The next driver starts the lap as soon as the previous driver finishes.
Find the team score.

Note

Time T And the lap timings of drivers are in the format DD:HH:MM:SS (where DD
=days, HH =hours , MM = minutes, ss =seconds)
Timings are in 24 hours format.

Input Format

The first line contains an integer N, denoting the number of drivers.


The second ne contains a string T, denoting the time.
The third line contains N space-separated strings, denoting the stack with the lap
timings of N drivers.

Sample Input

5 - - denotes N
01:03:00:20 - - denotes T
00:12:10:00 00:08:30:20 01:00:24:32 00:14:31:00 01:01:30:21 - - denotes a Stack

Constraints

1 <= N <= 100

Output Format
The output contains an integer denoting the team score.

Sample Output
2

Explanation
N=5
T = 01:03:00:00
We have a stack with elements:
01:01:30:21
00:14:31:00
01:00:24:32
00:08:30:20
00:12:10:00

For calculating the team score, we need to check the timings starting from the
first driver.
Hence, we need to reverse the strings in the stack.
After reversing, we have the following:

00:12:10:00
00:08:30:20
01:00:24:32
00:14:31:00
01:01:30:21

The first driver completes the race at 00:12:10:00, which is less than 01:03:00:20
(T).
Team score = 1.
The second driver completes the race at 00:08:30:20.
The total time becomes 00:20:40:20, which is less than 01:03:00:20 (7)
So, the final team score = 2.

Hence, the output is 2.

5. Problem Statement:
A playlist P of N songs is given. Each song has a unique integer rating assigned to it. Let's
assume you are at the ith song. You can skip to the jth song if j > i and the rating of song P[j] >
P[i]. Calculate the maximum number of skips you can make if you can start from any song in the
playlist.
Function Description: In the provided code snippet, implement the provided
maximumSkips(...) method using the variables to print the maximum number of skips you can
make if you can start from any song.

Input Format:
• The first line of the Input contains one integer denoting the size of the playlist.
• The second line of the input contains N integers denoting the ratings of the songs in the
playlist P.
Sample Input:
3 - denotes the N size of a playlist
1 0 2 -denotes ratings of songs in the playlist P[i]

Constraints: 1<=N<= 10 0<=P[i]<=10


Output Format: The output contains a single integer denoting the maximum number of skips.
Sample Output: 1
Explanation: If we start from the 1st song, then we can skip to the 3rd song only. If we start
from the 2nd song, then we can skip to the 3rd song. Hence, the output is 1.

6. Problem Statement:

Johnny has a multilevel toolbox where he keeps his tools. Each level of the toolbox has a
different number of slots in it. Each slot has exactly one tool i.e., a slot cannot be empty and, it
cannot have more than 1 tool. Johnny has written a number on each tool because he finds it
difficult to remember the names of all the tools. Find the number written on a tool kept in a
particular slot of a particular level in his toolbox.

Note: Levels are numbered from 1 to N where level 1 is the topmost level and N is the last level.
The number of slots in the ith level can be less than, greater than, or equal to the number of
slots in the (i-1)th level.

Input Format:
The first line contains an integer N, denoting the number of levels that Johnny's toolbox has.
The next N lines are as follows: The first integer M of each line denotes the number of slots in
that level and the next M integers denote the number written on each tool in array A. The last
line contains 2 space-separated integers X and Y, where X denotes the level in which the tool
lies, and Y denotes the slot of level X in which the tool is kept.
Sample Input:
2 — denotes N
3 1 9 2 — denotes M and elements of Array
42385
2 4 — denotes X and Y
Constraints: 1<=N<=5
1<=M<=5
0<=number written on each tool<=10
1<=X<=N
1<=Y<=size of level X
Output Format: The output contains a single integer denoting the number written on the tool
kept in the given location of Johnny's toolbox.
Sample Output: 5
Explanation:
In the given sample input, there are two levels. The first level has 3 slots, and the second level
has 4 slots. Numbers written on tools stored in level 1 are 192. Numbers written on tools stored
in level 2 are 2385. We want to find the number written on the tool stored in the 4th slot of the
2nd level. Hence, the output is 5.

You might also like