Q2. Maximum Length
You are given a string S of length N which consists of lower case English alphabets. You are given the Q update queries. Each query contains an integer X[i] and a character Y[i]. You have to update the character of the string S at index X[i] to Y[i] is set S[X[i]]=Y[i]. After the update of each query. You have to calculate the max length of the substring which is present in S and having the same characters. The substring should contain only 1 distinct character.
Eg:
N=6 S='ababcc' Q=3 X=[6,3,2] Y=['d','b','a']
Output: [1,3,2]
after 1st query
S[X[0]]=Y[0]
=> S = 'ababcd'
The substring 'a' contains only 1 distinct character and it has the maximum length of 1
after 2nd query
S[X[1]]=Y[1]
=> S = 'abbbcd'
The substring 'bbb' contains only 1 distinct character and it has the maximum length of 3
after 3rd query
S[X[2]]=Y[2]
=> S = 'aabbcd'
The substring 'aa' or 'bb' contains only 1 distinct character and it has the maximum length of 2
Hence [1,3,2]
Constraints N,Q -> 10^5
Q3. Class distribution
A school is having K classes namely 1,2,3...., k. N students want to take admission to the school. Students can give at most 2 consecutive classes as a preference for taking admission in any order separated by comma without space, given by the array Preference.Each student is assigned exactly one class. The capacity of each class is given by array Capacity. The total number of students assigned to each class should not exceed the capacity of that class.
Task
Determine whether all students can take admission in one of their preferred classes or not. Return YES or NO
Example
N=5
K=3
Capacity = [3,2,2]
Preference = ["3","3,2","2","2,1","2,3"]Output
YESConstraints N<= 10^5, K<=9