@@ -6,21 +6,48 @@ This is my attemp to make the coding experience easir for you guys so that you c
66## Preview
77
88
9- ## Todays 31-12-23
9+ ## Todays 01-01-24
10+
11+ # Intuition
12+ <!-- Describe your first thoughts on how to solve this problem. -->
13+ Unitary method.
14+
15+ # Approach
16+ <!-- Describe your approach to solving the problem. -->
17+ - I sorted both arrays - 'g' & 's'
18+ - Started from first element of 'g'
19+ - - checked from first element for element greater than 'g[ i] ' in 's[ j] '
20+ - - if found then incremented the count and nullify that 's[ j] ' so that that cookie cann't be considered in next child
21+ - Ran this loop for all elements of 'g'
22+ ---
23+ Have a look at the code , still have any confusion then please let me know in the comments
24+ Keep Solving.:)
25+
26+ # Complexity
27+ - Time complexity : $$ O(gs) $$
28+ <!-- Add your time complexity here, e.g. $$O(n)$$ -->
29+
30+ - Space complexity : $$ O(1) $$
31+ <!-- Add your space complexity here, e.g. $$O(n)$$ -->
32+
33+ # Code
1034```
1135class Solution {
12- public int maxLengthBetweenEqualCharacters(String s) {
13- int msl = -1; // maximum substring length
14- HashMap<Character, Integer> m = new HashMap<>();
15- for( int i = 0; i < s.length(); i++){
16- if( m.containsKey(s.charAt(i))){
17- msl = Math.max( msl, i - m.get(s.charAt(i)));
18- }
19- else{
20- m.put(s.charAt(i), i+1);
36+ public int findContentChildren(int[] g, int[] s) {
37+ // sorting both the arrays
38+ Arrays.sort(g);
39+ Arrays.sort(s);
40+ int c = 0; // to store the number of contended children
41+ for( int i = 0; i < g.length; i++){
42+ for( int j = 0; j < s.length; j++){
43+ if( s[j] >= g[i]){
44+ c++;
45+ s[j] = 0;
46+ break;
47+ }
2148 }
2249 }
23- return msl ;
50+ return c ;
2451 }
2552}
2653```
0 commit comments