Maximum Number of Workers with Equal Left and Right Shoes
Ellen would like to assign this task to her subordinate workers. Each worker should get a distinct interval of adjacent shoes, such that the number of left shoes is equal to the number of right shoes. Each shoe must be assigned to exactly one worker.
What is the maximum number of workers that Ellen can assign to this task?
Write a function:
class Solution { public int solution(String S); }
that, given a string S of letters "L" and "R", denoting the types of shoes in line (left or right), returns the maximum number of intervals such that each interval contains an equal number of left and right shoes.
Write an efficient algorithm for the following assumptions:
S is made only of the characters 'R' and/or 'L';S is the same.Another problem from the same batch: