Given a sequence of package sizes represented as a string of 'L' (large) and 'S' (small), find the length of the longest contiguous subsequence that has an equal number of 'L' packages and 'S' packages and starts and ends with the same package size.
Explanation: Step-by-step: Given the input 'LL', we initialize two pointers, left and right, to 0. We then enter a loop where we increment the count of 'L' packages and 'S' packages. However, since the counts are never equal and the subsequence does not start and end with the same package size, we return 0 as the longest contiguous subsequence length.
Explanation: Step-by-step: Given the input 'SSLS', we initialize two pointers, left and right, to 0. We then enter a loop where we increment the count of 'L' packages and 'S' packages. When the counts are equal and the subsequence starts and ends with the same package size, we update maxLen. In this case, maxLen is updated to 2 when the subsequence 'SS' meets the conditions.
Master coding challenges related to Two Pointers and solve the [Backup] Warehouse Packaging problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak