Maximum Number of Groups Entering a Competition LeetCode solution in Rust
1/// @author: Leon2/// https://leetcode.com/problems/maximum-number-of-groups-entering-a-competition/3/// Time Complexity: O(`len_gs`)4/// Space Complexity: O(1)5impl Solution {6pub fn maximum_groups(grades: Vec<i32>) -> i32 {7let len_gs: i32 = grades.len() as i32;8let mut cnt: i32 = 0;9// the running length of the (current) subarray10let mut len: i32 = 1;11// the accumulated sum of lengths (of subarrays)12let mut sum: i32 = 0;13while sum + len <= len_gs {14cnt += 1;15sum += len;16len += 1;17}18cnt19}20}