Scaler Topics Fortnightly Contest - 10 Editorial

This article is part of the Scaler Topics Fortnightly Contest - 10
Sheldon's Tie Breaker
Rajesh and Howard were arguing about what to watch on TV. They decided to settle it with a game of Rock, Paper, Scissors. When Sheldon jumped on saying "People familiar with each other tend to tie each other 70-80 percent of times."
He instead proposed to play a game of Rock, Paper, Scissor, Lizard, Spock. Where each player simultaneously choose one of the five using the respective sign.
He dictates rules as "Scissors cuts paper, paper covers rock, rock crushes lizard, lizard poisons Spock, Spock smashes scissors, scissors decapitates lizard, lizard eats paper, paper disproves Spock, Spock vaporizes rock, and as it always has, rock crushes scissors."
You are given two string A, B representing the choice of Rajesh and Howard respectively. Please tell whether winner is "Howard", "Rajesh" or "Tie".
Problem Constraints
Input Format
- First argument is string A representing choice of Rajesh.
- Second argument is string B representing choice of Howard.
Output Format
- Return a String representing winner or "Tie"
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: As 'Spock vaporizes rock', winner is Howard.
Explanation 2: Both are same; Tie.
Hint
- This is a simple Ad-Hoc problem. Just implement what is asked.
Complete Solution
Strange in Range
You are given 3 integers A, B and C. Find the count of integers in the range A to B (inclusive) which are strange with respect to C. An integer N is strange with respect to C if (N ⊕ C) < C.
Problem Constraints
Input Format
- The first argument is an integer A, the second argument is an integer B and the third and last argument is an integer C.
Output Format
- Return an integer denoting the count of integers in the range A to B (inclusive) which are strange with respect to C.
Example
Example Input Input 1:
Input 2:
Example Output Output 1:
Output 2:
Example Explanation Explanation 1: The integers from 1 to 5 that are strange with respect to 1 are 1, 2 and 3.
Explanation 2: There are no integers from 2 to 4 that are strange with respect to 1.
Hint
- Let MSB of N be at ith position
- N XOR C < C means that ith bit of C is 1.
Scaler Placement Report and Statistics
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Complete Solution
Minimum Expense to Reach Home
Given a undirected graph with an array A where A[i] represents value of node i. There is a 2-D vector B representing edges where each vector element has 2 values u,v representing there is edge from node u to node v. Node 1 is your current location and you have to reach Node E.
Now there is condition, you may pass through a edge uv only if abs(A[u]-A[v]) < C otherwise it will cost C coins to pass through that path once. Initially, you have D coins with yourself.
You have to tell the maximum coins from D which you may save while travelling from Node 1 to Node E.
Return -1 in case it is impossible to reach Node E with D coins.
Problem Constraints
Input Format
- First argument Integer array A representing value of nodes in the Graph.
- Second argument 2-D vector B representing edges in Graph.
- Third argument Integer C as per the question.
- Fourth argument Integer D representing total coins you have.
- Fifth argument Integer E representing your destination you have to reach finally.
Output Format
- You have to return the maximum possible coins you will have when you reach destination Node E.
- Return -1 in case cost to reach destination is more than D.
Example
Example Input Input 1:
Input 2:
Input 3:
Example Output Output 1:
Output 2:
Output 2:
Example Explanation Explanation 1: Path 1->2->3
Explanation 2: No path possible under 15 coins.
Explanation 3: Path 1->4->3
Turn Learning into Career Growth
Hint
- See if we can use bfs approach to solve the question. In case of abs(A[i]-A[j]) >= C we have to push the in front instead of back of the queue.
Complete Solution
Chocolate Boxes II
There are N chocolates and M boxes. The sweetness of each chocolate is given by an array A of size N, price of each chocolate is given by an array B of size N. Each chocolate is within a box and the box number for each chocolate is given by an array C of size N.
There is a price associated with each box as well which is given by an array D of size M. If you purchase a box, all chocolates inside it are also purchased and you don't have to pay for each chocolate inside it separately. You can purchase any chocolate separately or as part of a box.
The total sweetness is the sum of the sweetness of all chocolates purchased separately or as part of a box. You have E units of money. What is the maximum total sweetness you can get if you purchase chocolates optimally?
Problem Constraints
Input Format
- The first argument is an integer array A, the second argument is an integer array B, the third argument is an integer array C, the fourth argument is an integer array D and the fifth and last argument is an integer E.
Output Format
- Return an integer denoting the maximum total sweetness you can get if you purchase chocolates optimally?
Example
Example Input Input 1:
Input 2:
Example Output Output 1:
Output 2:
Example Explanation Explanation 1: You can purchase all the chocolates. First 2 as part of the box 1 costing 10 and the 3rd separately costing 1. Total sweetness = 2 + 1 + 2 = 5
Explanation 2: You can't purchase all chocolates. The optimal strategy is to purchase chocolate 1 giving sweetness = 10. You can purchase it both separately or as part of the box.
Hint
- Can you solve the solve the problem if you are allowed to purchase chocolates separately only?
- It is classical knapsack-dp problem.
- Can you extend the same idea to original problem?




