From 02ec559a0ed277cf47bce7f39c0823782f6a2ab8 Mon Sep 17 00:00:00 2001 From: Lam Phan Date: Tue, 14 Jan 2025 09:41:39 +0700 Subject: [PATCH] 3392 --- ...392_count_subarrays_of_length_three_with_a_condition.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 3301-3400/3392_count_subarrays_of_length_three_with_a_condition.rb diff --git a/3301-3400/3392_count_subarrays_of_length_three_with_a_condition.rb b/3301-3400/3392_count_subarrays_of_length_three_with_a_condition.rb new file mode 100644 index 0000000..2dc6961 --- /dev/null +++ b/3301-3400/3392_count_subarrays_of_length_three_with_a_condition.rb @@ -0,0 +1,7 @@ +# @param {Integer[]} nums +# @return {Integer} +def count_subarrays(nums) + nums.each_cons(3).count { |l,m,r| + 2 * (l + r) == m + } +end