0% found this document useful (0 votes)
457 views7 pages

DSA Mock Interview With Sharpener 1

You are given several problem statements involving donations, sorted arrays, strings, and password security. The donation problem involves calculating the extra amount each person donates in a group donation where later donors cannot pay less than previous donors. The sorted arrays problem involves finding the sum of differences between pairs of numbers from one array where the difference in positions matches a number in a second array. The smallest string problem is to generate the lexicographically smallest string using a subset of letters where each letter is used once and adjacent letters differ. The account security problem checks if a password meets criteria for containing various letter cases, digits, and special characters.
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)
457 views7 pages

DSA Mock Interview With Sharpener 1

You are given several problem statements involving donations, sorted arrays, strings, and password security. The donation problem involves calculating the extra amount each person donates in a group donation where later donors cannot pay less than previous donors. The sorted arrays problem involves finding the sum of differences between pairs of numbers from one array where the difference in positions matches a number in a second array. The smallest string problem is to generate the lexicographically smallest string using a subset of letters where each letter is used once and adjacent letters differ. The account security problem checks if a password meets criteria for containing various letter cases, digits, and special characters.
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
You are on page 1/ 7

1) Problem Statement:-

After the decimation, the world went into chaos. People had to rebuild the planet so
Shield came up with a donation strategy. They feel all the rich guys need to donate more
than the poor guys. So, they make a rule. They would make a donation list in which the
donation of each person would be shown. But the rule is that a person can’t pay less
than what has already been paid before them. Find the extra amount each person will
pay, and also, tell the shield the total amount of donation.
Input
The first line contains n, the total number of people donating. The next line contains n
space-separated integers denoting the amount of money paid by the people. The
amounts are mentioned in the order in which the people paid
Constraints:-
1 <= n <= 10^5
0 <= money <= 10^5
Output
The first line contains the total amount collected by the teacher at the end.

Example
Sample Input 1:-
10
1232436676
Sample Output 1:-
43

Explanation:-
0 0 0 1 0 1 0 0 0 1 is the extra amount paid by the people .to make 1 2 3 3 4 4 6 6 7 7

Sample Input 2:
8
12345678

Sample Output 2:
36

Sample Input 3:
5
299 288 277 266 255

Sample Output:
1495}

2) Problem Statement:-
You are given two sorted arrays A and B of size N and M respectively.
You have to find the value V, which is the summation of (A[j] - A[i]) for all pairs of i and j
such that (j - i) is present in array B.
You have two lists of numbers, A and B. Both lists are sorted. You want to find a value V
by doing a specific calculation with the numbers in list A. Here's how it works:

Simple Explanation-
You take a number from A (let's call it A[j]) and subtract another number from A (let's call
it A[i]). These two numbers are chosen in such a way that the difference between their
positions in the list (j - i) is one of the numbers in list B.
In simpler terms, for each number in list B, you want to find pairs of numbers in list A
where the difference between their positions in A matches the number from B. Then, you
subtract the smaller number from the larger number and add up all these differences.
That total is the value V you're looking for.

To do this, you're given the sizes of the arrays N and M (how many numbers are in each
list), the actual numbers in list A, and the numbers in list B.

The goal is to perform these calculations and find the value V according to the rules
explained above.

Input
The first line contains two space separated integers N and M – size of arrays A and B
respectively.
The second line contains N integers A1, A2, ... AN.
The third line contains M integers B1, B2, ... BM.

Constraints:
1 ≤ N ≤ 2×10^5
1≤M<N
1 ≤ A1 ≤ A2 ≤ ... ≤ AN ≤ 10^8.
1 ≤ B1 < B2 < ... < BM < N.
Output
Print a single integer, the value of V.
Example
Sample Input 1:
42
1234
13

Sample Output 1:
6
Sample Explanation 1:
Valid pairs of (i, j) are (1, 2), (2, 3), (3, 4), (1, 4).

Simple Input 2:
53
12379
6 13

Sample Output 2:
0
3) Problem Statement
Given N and K, find the lexicographically smallest string of length N using only the first K
lowercase letters of the alphabet such that each letter is used at least once and no two
adjacent characters are equal.
If such a string doesn't exist, print -1.

lexicographically 1:
-https://stackoverflow.com/questions/45950646/what-is-lexicographical-order
Lexicographically 2: - https://en.wikipedia.org/wiki/Lexicographic_order

Input
The first line of input contains a single integer, T (1 <= T <= 100).
Then T lines follow, each containing two space-separated integers, N (1 <= N <=
10^5) and K (1 <= K <= 26).
It is guaranteed that sum of N over all test cases does not exceed 10^6
Output
For each test case, output its answer in a new line.
Example
Sample Input:
2
23
32

Sample Output:
-1
aba

In the first test case, it's impossible to create a string of length 2 using 3 letters where
each letter must be used at least once. Hence, the output is -1. In the second test case,
we can create the string 'aba' using the first 2 letters of the alphabet (a, b) of length 3
where each letter is used at least once and no two adjacent characters are the same.

Sample Input 2:
1
73

Sample Output 2:
abababc
4) Problem Statement
Suresh is in the process of devising a secure password for his account. To ensure its
security, the password must meet the following prerequisites:
● It should encompass at least one lowercase letter from the set [a-z].
● It must feature a minimum of one uppercase letter from the range [A-Z],
positioned strictly within the password (excluding the first and last positions).
● The password should incorporate at least one digit from the set [0-9], placed
strictly within the password.
● It needs to include at least one special character selected from the set { '@', '#',
'%', '&', '?' }, positioned strictly inside.
● The password should have a length of at least 10 characters, though it is
permissible for it to be longer.

Suresh has generated multiple strings, and he seeks your assistance in verifying
whether the passwords adhere to the security criteria outlined above. Your task is to aid
Suresh in this endeavor.

Constraints:
1 ≤ |S| ≤ 20
All the characters in string S are one of the following: lower case letters [a-z], upper case
letters [A-Z], digits [0-9], special characters from the set { '@', '#', '%', '&', '?' }
Sum of the lengths of strings over all test cases is at most 10^6.

Your Task - You don't need to read input or print anything. Complete the function
accountOfSharpener() which has a single line of input, string S. Return output in a single
line "SECURE" if the password is secure and "NOT SECURE" if it is not.

Sample Input:
3
#showOff#P1
U@code4SHARPENER
gR3@tPWD

Sample Output:
NOT SECURE
SECURE
NOT SECURE

Explanation:
Example case 1:
In this situation, the given string fails to meet Condition 3. This is because the single digit
present in the string is not located strictly within the string boundaries. In order for
Condition 3 to be satisfied, the digit should be surrounded by characters on both sides.
Example case 2:
The second example case successfully fulfills all conditions. There are no issues with
any of the stated criteria, making this string a valid match.

Example case 3:
In the third case, Condition 5 is not met. This is due to the string's length being 8, which
exceeds the length limit specified in the condition. To satisfy Condition 5, the string's
length should be exactly 7 characters.

● Connect with Sharpener’s Mentor:


https://www.linkedin.com/in/abhishek-chauhan-10b4991b8/
1. Donation
2. Two Sorted Array
3. Smallest String 3
4. Suresh Account

You might also like