Given a list of recipe scores, where each score is either sweet (positive integer) or savory (negative integer), find the minimum length of a subarray that contains at least one sweet and one savory score. If no such subarray exists, return -1.
Explanation: Step-by-step: with input [3, -5, 2, -2, 1], we initialize two pointers, one at the start and one at the end of the subarray. We move the pointers towards each other until we find a sweet and a savory score. The length of the subarray is 5.
Explanation: Step-by-step: with input [-10], we try to find a subarray with both sweet and savory scores. Since there is only one score, we return -1.
Master coding challenges related to Two Pointers and solve the [Backup] Optimal Recipe Combination problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak