Toggle distribution
Intuition\n- Things to calcuate\n  - sum which yeilds min value\n  - toggle for that sum\n- Instead if we get distribution of \n  - toggle count on y axis\n  - 
# Intuition\n- Things to calcuate\n  - sum which yeilds min value\n  - toggle for that sum\n- Instead if we get distribution of \n  - toggle count on y axis\n  - sum on x axis\n- The solution will be min value of y axis\n- In this case marking edges and then using cummilative sum is helpful\n\n# Approach\n\n- keep a vector to store toggle distribution edges\n- for each pair `(x, y) or (y, x) with (x < y)` update toggle\n   - at 2 the count increase by 2 -> both x and y are to be decreased\n   - at x the count decrease by 1 -> keep x and decrease y\n   - at x+y the count decrease by 1 -> keep both same\n   - at x+y+1 the count increased by 1 -> keep y and increase x\n   - at y+limit+1 the count increased by 1 -> both x and y are to be increased\n- now find minmum cummulative sum from 2 to end of distribution\n\n- NOTE: the distribution for one pair is show in code\n- NOTE: the sum only start from 2 as min value of x or y has to be 2\n\n# Complexity\n\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```\nimpl Solution {\n    /// Special thanks to: https://github.com/vim-scripts/DrawIt\n    ///\n    /// Toggle distribution based for pair (x,y) with x < y\n    /// Based on final sum that is chosen\n    ///\n    ///                   [no toggle]\n    ///   [reduce]            0                [increase]\n    ///   [x & y ] [reduce y] | [increase x]   [ x & y  ]\n    ///   +-------+           v               +-----------+\n    ///   |       |-----------+---------------|           |\n    ///   |   2   |    1      |      1        |     2     |\n    ///   +-------+-----------+---------------+-----------+\n    ///  2       x           x+y     y + limit\n    ///  ----------------- final sum ---------------------->\n    ///\n    pub fn min_moves(nums: Vec<i32>, limit: i32) -> i32 {\n        let limit = limit as usize;\n        // max sum index = limit + limit + 1 when is y is limit\n        let mut toggle_edges = vec![0; 2 * limit + 2];\n        let mut nums = std::collections::VecDeque::from(nums);\n        while let (Some(a), Some(b)) = (nums.pop_front(), nums.pop_back()) {\n            let x = a.min(b) as usize;\n            let y = a.max(b) as usize;\n            // add only edges so total is got by cumulative sum\n            toggle_edges[2] += 2;\n            toggle_edges[x + 1] -= 1;\n            toggle_edges[x + y] -= 1;\n            toggle_edges[x + y + 1] += 1;\n            toggle_edges[y + limit + 1] += 1;\n        }\n\n        let mut min_moves = i32::MAX;\n        let mut toggles = toggle_edges.drain(..2).sum();\n        for toggle_edge in toggle_edges {\n            toggles += toggle_edge;\n            min_moves = min_moves.min(toggles);\n        }\n        min_moves\n    }\n}\n```
['Rust']