- Related Questions & Answers
- Check if it is possible to sort the array after rotating it in Python
- Check if it is possible to transform one string to another in Python
- Check if it is possible to serve customer queue with different notes in Python
- Check if it is possible to create a palindrome string from given N in Python
- Check if it is possible to create a polygon with a given angle in Python
- Check if it is possible to create a polygon with given n sidess in Python
- Is it possible in Android to check if a notification is visible or canceled?
- Is it possible to check if a String only contains ASCII in java?
- Check if it is possible to convert one string into another with given constraints in Python
- Check if it is possible to rearrange rectangles in a non-ascending order of breadths in Python
- Check if it possible to partition in k subarrays with equal sum in Python
- Check if it is possible to draw a straight line with the given direction cosines in Python
- Check if it is possible to form string B from A under the given constraint in Python
- Check if it is possible to rearrange a binary string with alternate 0s and 1s in Python
- Check if it is possible to sort an array with conditional swapping of adjacent allowed in Python

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose there is an island. There is only one store in that location, this store remains open always except Sunday. We have following values as input −

- N (Maximum number of food someone can buy each day).
- S (Number of days someone is required to survive).
- M (Number of food required each day to survive).

If it is Monday, and we need to survive for the next S number of days. We have to check whether we can survive or not, if we can find the minimum number of days on which we need to buy food, so that we can survive the next S number of days.

So, if the input is like S = 12, N = 24, M = 3, then the output will be True and minimum number of days on which we need to buy food is 2, as we can survive 8 days (from current Monday to next Monday) using 24 units of food, then buy again 12 units for next 4 days.

To solve this, we will follow these steps −

- if (N * 6 < M * 7 and S > 6) or M > N, then
- return False

- otherwise,
- count := quotient of (M * S) / N
- if (M * S) is divisible by N, then
- count := count + 1

- return True and count

Let us see the following implementation to get better understanding −

def solve(S, N, M): if ((N * 6) < (M * 7) and S > 6) or M > N: return False else: count = (M * S) // N if ((M * S) % N) != 0: count += 1 return (True, count) S = 12 N = 24 M = 3 print(solve(S, N, M))

12, 24, 3

(True, 2)

Advertisements