Rust | Bottom-up DP, One-Pass, no extra space
Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n\npub fn solve(\n    vec_0: Vec<u32>,\n    vec_1: Vec<u32>,\n) -> usize {\n    let 
# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(1)$$\n\n# Code\n```\npub fn solve(\n    vec_0: Vec<u32>,\n    vec_1: Vec<u32>,\n) -> usize {\n    let mut dp = [usize::MIN, 1];\n\n    for i in 1..vec_0.len() {\n        let (e0, e1) = (vec_0[i], vec_1[i]);\n        let (p0, p1) = (vec_0[i - 1], vec_1[i - 1]);\n\n        let mut dp_next = [usize::MAX; 2];\n        \n        if p0 < e0 && p1 < e1 {\n            dp_next[0] = dp_next[0].min(dp[0]);\n            dp_next[1] = dp_next[1].min(dp[1] + 1);\n        } // try not swapping\n        \n        if p1 < e0 && p0 < e1 {\n            dp_next[0] = dp_next[0].min(dp[1]);\n            dp_next[1] = dp_next[1].min(dp[0] + 1);\n        } // try swapping\n\n        dp = dp_next;\n    }\n\n    *dp.into_iter().min().unwrap()\n}\n\nimpl Solution {\n    fn preproc(vec: Vec<i32>) -> Vec<u32> {\n        vec.into_iter()\n            .map(|e| e as u32)\n            .collect::<Vec<_>>()\n    }\n\n    pub fn min_swap(vec_0: Vec<i32>, vec_1: Vec<i32>) -> i32 {\n        let vec_0 = Self::preproc(vec_0);\n        let vec_1 = Self::preproc(vec_1);\n\n        solve(vec_0, vec_1) as i32\n    }\n}\n```
['Dynamic Programming', 'Rust']