Problem Statement:
Write a function all_subarrays(arr)
that uses backtracking to generate all possible subarrays (contiguous subsequences) of a given array.
Example:
Input: [1, 2, 3]
Output: [[], [1], [2], [3], [1, 2], [2, 3], [1, 2, 3]]
Problem Statement:
Write a function subarrays_with_sum(arr, target)
that uses backtracking to find all subarrays whose elements sum up to a given target value.
Example:
Input: arr = [1, 2, 3, 4, 5], target = 9
Output: [[2, 3, 4], [4, 5]]
Problem Statement:
Write a function subarrays_with_product_less_than_k(arr, k)
that uses backtracking to find all subarrays whose elements have a product less than k.
Example:
Input: arr = [10, 5, 2, 6], k = 100
Output: [[10], [5], [2], [6], [10, 5], [5, 2], [2, 6], [5, 2, 6]]
Problem Statement:
Write a function subarrays_with_max_diff_less_than_k(arr, k)
that uses backtracking to find all subarrays where the difference between the maximum and minimum elements is less than k.
Example:
Input: arr = [1, 3, 6, 10, 15], k = 5
Output: [[1], [3], [6], [10], [15], [1, 3], [3, 6], [6, 10], [10, 15]]
Problem Statement:
Write a function subarrays_with_equal_odd_even(arr)
that uses backtracking to find all subarrays having an equal number of odd and even elements.
Example:
Input: arr = [1, 2, 3, 4, 5]
Output: [[1, 2], [2, 3], [3, 4], [4, 5], [1, 2, 3, 4], [2, 3, 4, 5]]