Gaming Array 1

  • + 0 comments

    Rust best solution

    If you’re looking for solutions to the 3-month preparation kit in either Python or Rust, you can find them below: my solutions

    fn gaming_array(arr: &[i32]) -> String {
        //Time complexity: O(n)
        //Space complexity (ignoring input): O(1)
        let mut max_number = arr[0];
        let mut turns = 0;
        for &number in arr {
            if number > max_number {
                max_number = number;
                turns += 1
            }
        }
        if turns % 2 == 0 {
            String::from("BOB")
        } else {
            String::from("ANDY")
        }
    }