853. Maximum Sized Array
Given a positive integer s, define a 3D array A of dimensions n ร n ร n, where each element is computed as: A[i][j][k]=iร(j OR k) , 0 <= i, j, k < n.
Return the largest possible value of n such that the sum of all elements in the array does not exceed s.
Example 1:
Input: s = 20
Output: 2
Explanation:
Elements of the array A for n = 2:
A[0][0][0] = 0 * (0 OR 0) = 0ย ย
A[0][0][1] = 0 * (0 OR 1) = 0ย ย
A[0][1][0] = 0 * (1 OR 0) = 0ย ย
A[0][1][1] = 0 * (1 OR 1) = 0ย ย
A[1][0][0] = 1 * (0 OR 0) = 0ย ย
A[1][0][1] = 1 * (0 OR 1) = 1ย ย
A[1][1][0] = 1 * (1 OR 0) = 1ย ย
A[1][1][1] = 1 * (1 OR 1) = 1ย ย
The total sum of elements in A is 3, which does not exceed 20.
Trying n = 3 would exceed s, so the answer is 2.
Example 2:
Input: s = 5
Output: 2
Explanation:
Using the same calculations as in Example 1, the total sum for n = 2 is 3, which fits within s = 5.
Since n = 3 would exceed s, the answer remains 2.
Now Your Turn!
Pick the correct output for the given inputInput: s = 100
Still unsure what the problem is asking ?
Letโs go through a few more examples, step by step, to make it clearer.
Constraints:
- 0 <= s <= 1015