Problem Description :
The function accepts two positive integers ‘r’ and ‘unit’ and a positive integer array ‘arr’ of size ‘n’ as its argument ‘r’ represents the number of rats present in an area, ‘unit’ is the amount of food each rat consumes and each ith element of array ‘arr’ represents the amount of food present in ‘i+1’ house number, where 0 <= i
Note:
Return -1 if the array is null
Return 0 if the total amount of food from all houses is not sufficient for all the rats.
Computed values lie within the integer range.
Example:
Input:
r: 7
unit: 2
n: 8
arr: 2 8 3 5 7 4 1 2
Output:
4
Explanation:
Total amount of food required for all rats = r * unit
= 7 * 2 = 14.
The amount of food in 1st houses = 2+8+3+5 = 18. Since, amount of food in 1st 4 houses is sufficient for all the rats. Thus, output is 4.
Benefits of TheCodeground Online IDE
Multi-Language Support
TheCodeground Online IDE supports C++, Java, Node.js, Python, and more, making it an incredibly versatile tool for diverse coding needs. This extensive language support allows developers to work on different projects within a single platform.
Real-Time Collaboration
Our real-time collaboration feature enables multiple developers to work on the same project simultaneously, enhancing teamwork and productivity. This feature is particularly beneficial for remote teams and pair programming sessions.
User-Friendly Interface
Designed with a clean and intuitive interface, TheCodeground Online IDE simplifies coding and debugging processes, making it accessible for users of all skill levels. The ease of use and clear navigation ensure a smooth coding experience.
Instant Code Execution
Experience fast and efficient code execution with immediate feedback in the integrated terminal. This feature helps streamline the development process, allowing developers to quickly test and debug their code.
Free to Use
Enjoy the full range of features at no cost. TheCodeground Online IDE is completely free, providing a valuable resource for developers without any subscription fees. This makes it an ideal choice for students, hobbyists, and professionals alike.
Cloud-Based Platform
As a cloud-based IDE, TheCodeground allows you to access your projects from anywhere, at any time. This flexibility ensures that you can continue coding without being tied to a specific device or location.
Customizable Environment
Tailor the IDE to your preferences with customizable themes, layouts, and extensions. This personalization ensures a comfortable and productive coding environment.
Why Choose TheCodeground Over Other Online IDEs?
TheCodeground Online IDE stands out from the competition with its comprehensive feature set, ease of use, and cost-effectiveness. Unlike many other online IDEs that require subscriptions or offer limited free plans, TheCodeground provides all its features for free. Our multi-language support, real-time collaboration, and advanced debugging tools ensure that you have everything you need for effective development. Additionally, our user-friendly interface and customizable environment make coding a pleasant experience, regardless of your expertise level. Choose TheCodeground Online IDE for a seamless, efficient, and enjoyable coding experience.