Answers for "Find the minimum product among all combinations of triplets in a list"

0

Find the minimum product among all combinations of triplets in a list

// Find the minimum product among all combinations of triplets in a list

fn find_min_triplet_product( arr: [i32; 5]) {
    let n = arr.len();
    let mut min_prod = i32::max_value();
	for i in 0..n-2 {
	    for j in i+1..n-1 {
	        for k in j+1..n {
	            let prod = arr[i] * arr[j] * arr[k];
	            if prod < min_prod {
	                min_prod = prod;
                }
            }
        }
	}
	println!("minprod {}", min_prod);
}

fn main() {
    let arr: [i32; 5] = [1, 4, 10, -2, 4 ]; // answer -80
    find_min_triplet_product(arr)
}
Posted by: Guest on August-24-2021

Code answers related to "Find the minimum product among all combinations of triplets in a list"

Browse Popular Code Answers by Language