[Rust] O(N) 1 pass 0ms simple solution
A naive way will be: \n1. sort the vector \n2. multiply (max - 1) * (second_max - 1)\n\nrust\nimpl Solution {\n    pub fn max_product(ref mut nums: Vec<i32>) ->
A naive way will be: \n1. sort the vector \n2. multiply `(max - 1) * (second_max - 1)`\n\n```rust\nimpl Solution {\n    pub fn max_product(ref mut nums: Vec<i32>) -> i32 {\n        nums.sort();\n        (nums.last().unwrap() - 1) * (nums[nums.len() - 2] - 1)\n    }\n}\n```\n\nBut I guess the interviewer will not like it since time complexity of sort is `O(n log n)`. For weekly contests, it does not matter what algorithm you choose as long as it does not cause `LTE`. But when you talk with others on this problem, I recommend the following`O(n)` method. \n\n\n```rust\nimpl Solution {\n    pub fn max_product(nums: Vec<i32>) -> i32 {\n        let (mut ma, mut mb) = (0, 0);\n        for n in nums.iter() {\n            if *n > ma {\n                mb = ma; \n                ma = *n; \n            } else {\n                mb = max(mb, *n);\n            }\n        }\n        (mb - 1) * (ma - 1)\n    }\n}\n```\n\n
[]