Java Bit Manipulation Memoization Sliding Window
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n   public int[] smallestSubarrays(int[] nums) {\n\n        // 0. \uAC01 index\uC5D0\uC11C \uC2DC\uC791\uD574\uC11C or\uC5F0\uC0B0\uC744 \uD574\uB098\uAC14\uC744 \uB54C \uAC00\uC9C8 \uC218 \uC788\uB294 \uCD5C\uB300 \uAC12\uC774 \uC788\uACE0\n        //     \uADF8 \uCD5C\uB300\uAC12\uC744 \uB2EC\uC131\uD558\uAE30 \uC704\uD55C \uAC00\uC7A5 \uC9E7\uC740 subarray\n        \n        // 1. \uAC01 \uC790\uB9AC\uB9C8\uB2E4 \uAC00\uC9C8 \uC218 \uC788\uB294 max\uAC12\uB4E4\uC744 \uBBF8\uB9AC \uAD6C\uD574\uB193\uB294\uB2E4.  \n        //   \u203B \uC2DC\uC791\uC810\uC774 \uB2E4\uB974\uAE30 \uB54C\uBB38\uC5D0 \uAC00\uC9C8 \uC218 \uC788\uB294 \uCD5C\uB300\uAC12\uC774 \uAC01\uAC01 \uB2E4\uB974\uB2E4. \n\n        // 2. sliding windows \uB85C \uAD6C\uD55C\uB2E4. \n        //   \uD604\uC7AC\uC758 bitmask\uAC12\uC744 max[start] \uC640 \uBE44\uAD50\uD55C\uB2E4. \n        //   \u203B \uC2DC\uC791\uC810\uC774 start\uC774\uACE0 bitmask\uAC00 max[start]\uB791 \uAC19\uC73C\uBA74 \n        //      \uD574\uB2F9 \uAE38\uC774\uB97C result[start]\uC5D0 \uC800\uC7A5\n\n        // \u203B bit\uC5F0\uC0B0 \uAC12\uC744 sliding window\uD560 \uB54C \uAC01 \uC790\uB9AC bit\uC758 \uAC1C\uC218\uB97C \uC720\uC9C0\uD574\uC8FC\uBA74\uC11C \uACC4\uC0B0\uD574\uC900\uB2E4.\n\n\n        int n = nums.length;\n     \n        int result[] = new int[n];\n\n        int max[] = new int[n];\n        int m = 0;\n        for(int i = n-1; i >= 0; i--) {\n            m |= nums[i];\n            max[i] = m;\n        }\n\n\n        int count[] = new int[30];\n        int start = 0;\n        int bitmask = 0;\n        for(int i = 0; i < n; i++) {\n            bitmask = add(count, nums[i]);\n\n            while( start <= i && bitmask == max[start] ) {\n                result[start] = i-start+1;\n                bitmask = remove(count, nums[start]);\n                start++;\n\n                // for(int j = 0; j < result.length; j++) System.out.print(result[j] + ","); System.out.println();\n            }\n\n            // System.out.println(i + " " +bitmask);\n        }\n\n        return result;\n    }\n\n    private int add(int count[], int num) {\n        \n        int bitmask = 0;\n        for(int i = 0; i < 30; i++) {\n            if ( (num & ( 1 << i)) > 0 ) count[i]++;\n            if (count[i] > 0 ) bitmask |= (1 << i);\n        }\n\n        return bitmask;\n    }\n\n    private int remove(int count[], int num) {\n        int bitmask = 0;\n        for(int i = 0; i < 30; i++) {\n            if ( (num & ( 1 << i)) > 0 ) count[i]--;\n            if ( count[i] > 0 ) bitmask |= (1 << i);\n        }\n\n        return bitmask;\n    }\n\n}\n```
['Bit Manipulation', 'Memoization', 'Sliding Window', 'Java']