Scaler Topics Fortnightly Contest - 9 Editorial

This article is part of the Scaler Topics Fortnightly Contest - 9
Water Transportation
There are N warehouses in a water housing facility. Each warehouse contains Ai water containers, and each container has Bi litres of water. Your Truck can transport only C containers of water from the facility. Determine the maximum amount of water that you can transport from the facility.
Problem Constraints
Input Format
- First argument is the array A
- Second argument is the array B
- Third argument is an integer C
Output Format
- Return an integer, denoting the maximum amount of water that you can transport from the facility.
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:
We will take 1 container each from 1st, 3rd and 4th warehouse and 2 containers from 2nd warehouse. Hence 10 + 6 + 3 + 10 = 29
Explanation 2: Take 2 containers from 3rd warehouse and 3 containers from 5th warehouse. Hence 14 + 12 = 26 litres.
Hint
- Try to Think greedy.
- Try to think how sorting the array will help.
Complete Solution
Perfect AND
You are given an integer array A. Return 1 if there is a subarray in A such that Bitwise And of all elements in the subarray is equal to B else, return 0.
Problem Constraints
Input Format
- The first argument is an integer array A.
- The second argument is an integer B.
Output Format
- Return an integer.
Example
Example Input
Input 1:
Input 2:
Example Output
Output 1:
Output 2:
Example Explanation
Explanation 1:
We can select the subarray [3, 5].
(3 & 5) = 1
Explanation 2: There's no way to get 3 by selecting any subarray.
Hint
- How the values of AND function will behave if we increase the length of our subarray by adding elements to subarray for either side.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Complete Solution
How Many Strings
A string is called good if there doesn't exist a subarray of length greater than B in which all characters are the same. Return the number of good strings of length A, the answer can be very large so return modulo 109+7.
NOTE: The string should only contain lowercase Latin alphabets.
Problem Constraints
Input Format
- The first argument is an integer A.
- The second argument is an integer B.
Output Format
- Return an integer.
Example
Example Input
Input 1:
Input 2:
Example Output
Output 1:
Output 2:
Example Explanation
Explanation 1: We can place any character at first position in the string but can only place different character at next position. So choice for first position 26, then choice for second position 25. Therefore, .
Explanation 2: We can place any character at any position. So, .
Turn Learning into Career Growth
Hint
- Let's build the string character by character.
- While adding characters to end of the string we only care about the last character and it's previous continuous occurrence.
Complete Solution
Get Out
You are in the country of Marley. The country have A cities and the cities are connected with A-1 bidrectional roads such that it is possible to reach any city from other city in the country. You want to get out of the country as you've heard titans will be invading the country soon. To get out you need to reach one of the coastal cities. Coastal cities are those cities which from which only one road is connected. Find the minimum time for all the cities to reach a coastal city. Roads connecting two cities are represented by the matrix B, where for ith road, B[i][0] and B[i][1] represent the cities connected by a bidirectional road and B[i][2] represents the time required to travel through this road.
Problem Constraints
Input Format
- The first argument is an integer A.
- The second argument is a 2D integer array B.
Output Format
- Return an integer array.
Example
Example Input
Input 1:
Input 2:
Example Output
Output 1:
Output 2:
Example Explanation
Explanation 1: The coastal cities are 1 and 3 as they are connected by only one road. From city 2 city 1 one is closest with distance 5.
Explanation 2: The coastal cities are 3, 4 and 5. From 1 city 3 is closest. From 2 city 3 is closest.
Hint
- The problem converts to shortest path question from some special nodes.




