✅ [Rust] 26 ms, fastest (100%) one-pass solution (with detailed comments)
This solution employs a one-pass algorithm to update first-occurence positions of bits. It demonstrated 26 ms runtime (100.00%) and used 3.5 MB memory (80.29%).
This [**solution**](https://leetcode.com/submissions/detail/810097381/) employs a one-pass algorithm to update first-occurence positions of bits. It demonstrated **26 ms runtime (100.00%)** and used **3.5 MB memory (80.29%)**. Detailed comments are provided.\n\n**IF YOU LIKE THIS SOLUTION, PLEASE UPVOTE.**\n```\nimpl Solution \n{\n    pub fn smallest_subarrays(nums: Vec<i32>) -> Vec<i32> \n    {\n        let mut ret: Vec<i32> = vec![1;nums.len()];\n        \n        // [1] when performing OR operation on an array, \n        //     we care only about the first occurence of each bit,\n        //     because all subsequent occurences do not change the result;\n        //     thus, we should arrange a storage \'bit_idx\' for the positions of \n        //     the first occurence of each bit; \n        let mut bit_idx: [i32;30] = [0;30];\n\n        let mut max_pos : i32;\n        let mut bit     : i32;\n        \n        // [2] for a one-pass solution, we iterate over \'nums\' from the end;\n        //     this allows us to dynamically update the first occurence of bits;\n        //     terminal zeros are skipped, their respective minimal subarray size is 1\n        for (pos, &n) in nums.iter().enumerate().rev().skip_while(|(_,n)| **n == 0)\n        {\n            // [3] for each bit, update the earliest/first position it was seen at;\n            //     here we use an arithmetic way to update \'bit_idx\',\n            //     use of conditional statement is slower\n            for b in 0..30\n            {\n                bit = (n >> b) & 1;\n                bit_idx[b] = (1 - bit) * bit_idx[b] + bit * (pos as i32);\n            }\n\n            // [4] minimal subarray/window is the one that accounts for all bits\n            //     that were seen at least once \n            max_pos = *bit_idx.iter().max().unwrap();\n            ret[pos] = max_pos - pos as i32 + 1;\n        }\n        \n        return ret;\n    }\n}\n```
['Rust']