JS | Two approach | Math (or) Binary search | O(1) | Beats 100% 🚀
ApproachJust maths.Complexity
Time complexity: O(1)
Space complexity: O(1)
CodeApproachWe can use Binary Search algorithm which efficiently searches for the max
# Approach
Just maths.

# Complexity
- Time complexity: O(1)
- Space complexity: O(1)

# Code
```javascript []
var maxContainers = function(n, w, m) {
    if((n * n * w) <= m) return n * n;
    return Math.floor(m / w);
};
```


# Approach
We can use Binary Search algorithm which efficiently searches for the maximum number of containers by checking the mid-point.

# Complexity
- Time complexity: O(log(n))
- Space complexity: O(1)

# Code
```javascript []
var maxContainers = function(n, w, m) {
    let l = 1, r = n*n, res = 0;
    while(l <= r) {
        const mid = Math.floor((l+r)/2);
        if (mid*w <= m) {
            res = mid;
            l = mid+1;
        } else {
            r = mid-1;
        } 
    }
    return res;
};
```

['JavaScript']