You are building a slideshow from the photos on your phone. Each photo is either portrait ('P') or landscape ('L'). The string photos gives their orientations in the order the photos were taken.
A smooth transition happens when the slideshow moves from one photo to the next and both photos have the same orientation. When the orientation changes, the screen has to rotate, so that transition is not smooth.
You may remove any number of photos, including none, but you cannot reorder the photos you keep. The kept photos are shown one after another.
Return the maximum number of smooth transitions the slideshow can have.
int maxSmoothTransitions(String photos)
photos is the orientation of each photo, in the order the photos were taken.0 transitions.1 ≤ photos.length() ≤ 200,000photos is 'P' or 'L'.Input: maxSmoothTransitions(photos = "LPLLPL")
Output: 3
Explanation: Remove both portrait photos. The slideshow becomes "LLLL", which has 3 smooth transitions.
Input: maxSmoothTransitions(photos = "LPPPLLLL")
Output: 5
Explanation: Keep every photo. "PPP" gives 2 smooth transitions and "LLLL" gives 3, for a total of 5.
Input: maxSmoothTransitions(photos = "LLLPLPPPP")
Output: 6
Explanation: Remove the portrait photo at index 3 (0-based). The slideshow becomes "LLLLPPPP", with 3 smooth transitions among the landscape photos and 3 among the portrait photos.
Input: maxSmoothTransitions(photos = "PLLPL")
Output: 2
Explanation: Keeping every photo gives only 1 smooth transition. Remove both portrait photos to get "LLL", which has 2 smooth transitions.
Input: maxSmoothTransitions(photos = "P")
Output: 0
Explanation: There is only one photo, so there are no transitions.