Jar of Candies Problem Statement
You are given a jar containing candies with a maximum capacity of 'N'. The jar cannot have less than 1 candy at any point. Given 'K', the number of candies a customer wants, determine how many candies remain in the jar after providing the desired count.
If 'K' is greater than 'N', consider the order invalid and return -1.
Input:
T (number of test cases)
For each test case:
N K (number of candies in the jar and number of candies requested)
Output:
The number of candies left in the jar or -1 if the request is invalid. Output each result on a new line for each test case.
Example:
Input:
1
10 5
Output:
5
Explanation:
With 'N' = 10 and 'K' = 5, after giving away 5 candies, 5 candies remain in the jar.
Constraints:
- 1 <= T <= 5
- 1 <= N, K <= 10^4
Time Limit: 1 second
Note:
Focus on implementing the function; printing is managed elsewhere.
Be the first one to answer
Add answer anonymously...
Top TCS iON Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app