Scaler Topics Fortnightly Contest - 8 Editorial

This article is part of the Scaler Topics Fortnightly Contest - 8.
Weird Language
You visit a very special village which has a weird language. In their language the order of lowercase alphabets is decided by the frequency of letters in the special string A, incase of clash of frequencies, put in order according to english alphabets. If a letter does not appear in the special string its frequency is said to be 0.
You are given a string B and you need to return the string obtained after sorting B in decreasing order according to above ordering. Refer to samples for more clarity.
Problem Constraints
Input Format
- First agrument A is a string according to which alphabets are sorted.
- Second agrument B is a string which needs to be sorted.
Output Format
- Return a single string after sorting B according to above rules.
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
Example
Example Input
Input 1:
Input 2:
Example Output
Output 1:
Output 2:
Example Explanation
Explanation 1:
'c' occurs most frequently (3 times) that's why it comes first then 'a' (2 times) , 'b' then 'x', 'y' & 'z' in their natural order as all have frequency equal to zero.
Explanation 2: Only 'z' is present in special string so it comes first and rest in their natural order.
Hint
- Can you think of using a hashmap?
- What can be the comparator function?
Complete Solution
Add Everything
Alice and Bob are playing a game. Alice will give a string A and a string B, both consisting of characters between (1 - 9). Bob can insert '+' anywhere in the string (possibly none or any number of times) and compute the values. Bob will compute all such possiblity and find their sum. If this is equal to the second string B given by Alice, then Alice wins, otherwise Bob wins. Help them to find out who wins.
Problem Constraints
Input Format
- The first argument is the String A.
- The second argument is the String B.
Output Format
- Return a string "Alice win" if Alice wins, "Bob win" otherwise.
Example
Example Input
Input 1:
Input 2:
Example Output
Output 1:
Output 2:
Example Explanation
Explanation 1:
if A = 125 and B = 176:
The possiblities to insert '+' are .
Thus, the sum is .
As this is equal to the String B, Alice wins.
Explanation 2:
The different possibilites are:
This is not equal to 145. Therefore, Bob wins.
Hint
- For a number of length N, there are 2N - 1 different possible cases.
- If we use binary representation, 0000, 0001, 0010.
- Here, 0 represents absent and 1 represent present,which we can use to say whether '+' is present or absent.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Complete Solution
Dramatics Group
Ms. Malni wants to create groups of students for an Inter-School Dramatics competition. There are a total of N sections with Ai number of students in each section. Each group should have at least B number of students. There can be no more than C students in a group from the same section, i.e., no more than C students from the same section belong to the same group.
Note: It is possible that some students are not included in any group.
Help Ms. Malni find the maximum number of groups she could form. As the answer can be very large, return the remainder after diving the result with 109+7 .
Problem Constraints
Input Format
- The first argument is an integer array A. Representing the number of students in each section.
- The second argument is an integer B. Representing the minimum size of the group.
- The third argument is an integer C. Representing that no more than C students can be in a group from the same section.
Output Format
- Return an integer denoting the maximum number of groups that can be formed.
Example
Example Input
Input 1:
Input 2:
Example Output
Output 1:
Output 2:
Example Explanation
Explanation 1:
Possible two groups are
Explanation 2: Possible two groups are .
Note:
- The number represents the student's section in the above-given explanation.
Turn Learning into Career Growth
Hint
- If it is possible to create X number of groups, we can also make less than X groups.Hence we can use Binary Search.
Complete Solution
Empty Buckets
Mr. Naaya has N number of buckets, and each bucket has a volume given by Ai and the amount of water it holds given by Bi.
Mr. Naaya wants to get the maximum number of empty buckets. Moreover, he has to do so as soon as possible. Mr. Naaya takes x seconds to pour x units of water from one bucket to another.
A bucket can’t hold water greater than its volume; no water should be wasted.
Help Mr. Naaya find the maximum number of empty buckets he could get in the minimum possible time.
Problem Constraints
Input Format
- The first argument is an integer array A. Representing the volume of the ith bucket.
- The second argument is an integer array B. Representing the amount of water in the ith bucket.
Output Format
- Return an array of integers of size two, where the first element denotes the maximum number of empty buckets that Mr. Naaya can get, and the second element represents the minimum time required to get the maximum number of empty buckets.
Example
Example Input Input 1:
Input 2:
Example Output
Output 1:
Output 2:
Example Explanation
Explanation 1:
Transfer 3 units of water from the first bucket to the third bucket which takes 3 seconds,Then transfer 4 units of water from the second bucket to the third bucket, which takes 4 units of time.
Hence, a maximum of 2 empty buckets in a minimum time of 7 seconds.
Explanation 2: All buckets are completely filled, hence 0 empty buckets.
Hint
- Think of finding the minimum number of buckets required to fill the water.
- Use Dynamic Programming to get the minimum number of buckets and the time required.
- Let the states of DP be .




