Problem Statement 18:
Prakhar has a strings of length n containing only characters "J"L" and "R". He wants to find the length of the smallest substring, which satisfies the following condition:
Length of the substring is at least 2 'J' occurs strictly more times in this substring than 'L'. 'J' occurs strictly more times in this substring than 'R'
Prakhar is busy planning designs in Jaguar F-Pace, help
him solve the problem.
A substring is a contigudus sequence of characters within a string.
Constraints: length of string s is n and 2 <= n <= 10^6
Input: The first line contains the length of strings i.en Second line contains the strings consisting only letters "", "L" and "R"
Output: print in a single line the length of the smallest substring which satisfies all the above conditions. output-1 if there is no such substring.
Sample Test Case 1:
Input:
2
JJ
Expected Output:
2
Sample Test Case 2:
Input:
8
Expected Output:
3
Sample Test Case 3:
Input:
5
RLJLL
Expected Output: -1