3344. Maximum Sized Array πŸ”’ 

δΈ­ζ–‡ζ–‡ζ‘£

Description

Given a positive integer s, let A be a 3D array of dimensions n × n × n, where each element A[i][j][k] is defined as:

  • A[i][j][k] = i * (j OR k), where 0 <= i, j, k < n.

Return the maximum possible value of n such that the sum of all elements in array A does not exceed s.

 

Example 1:

Input: s = 10

Output: 2

Explanation:

  • Elements of the array A for n = 2:
    <ul>
    	<li><code>A[0][0][0] = 0 * (0 OR 0) = 0</code></li>
    	<li><code>A[0][0][1] = 0 * (0 OR 1) = 0</code></li>
    	<li><code>A[0][1][0] = 0 * (1 OR 0) = 0</code></li>
    	<li><code>A[0][1][1] = 0 * (1 OR 1) = 0</code></li>
    	<li><code>A[1][0][0] = 1 * (0 OR 0) = 0</code></li>
    	<li><code>A[1][0][1] = 1 * (0 OR 1) = 1</code></li>
    	<li><code>A[1][1][0] = 1 * (1 OR 0) = 1</code></li>
    	<li><code>A[1][1][1] = 1 * (1 OR 1) = 1</code></li>
    </ul>
    </li>
    <li>The total sum of the elements in array <code>A</code> is 3, which does not exceed 10, so the maximum possible value of <code>n</code> is 2.</li>
    

Example 2:

Input: s = 0

Output: 1

Explanation:

  • Elements of the array A for n = 1:
    <ul>
    	<li><code>A[0][0][0] = 0 * (0 OR 0) = 0</code></li>
    </ul>
    </li>
    <li>The total sum of the elements in array <code>A</code> is 0, which does not exceed 0, so the maximum possible value of <code>n</code> is 1.</li>
    

 

Constraints:

  • 0 <= s <= 1015

Solutions