Assign Cookies

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie.
Each child i has a greed factor g[i], which is the minimum size of a cookie that the child will be content with; and each cookie j has a size s[j]. If s[j] >= g[i], we can assign the cookie j to the child i, and the child i will be content. Your goal is to maximize the number of your content children and output the maximum number.
LeetCode Problem: Link | Click Here
class Solution {
public int findContentChildren(int[] g, int[] s) {
// Sort the arrays in ascending order
Arrays.sort(g);
Arrays.sort(s);
int outPut = 0; // Counter to track the number of content children
// Loop through the children's greed factors
for (int i = 0; i < g.length; i++) {
// Iterate through the available cookies sizes
for (int j = 0; j < s.length; j++) {
// If the cookie size is greater than or equal to the child's greed factor
if (s[j] >= g[i]) {
outPut++; // Increment the count of content children
s[j] = -1; // Mark the used cookie as '-1' to avoid reusing it
break; // Move to the next child after finding a suitable cookie
}
}
}
return outPut; // Return the count of content children
}
}




