iamalwayshappy's blog

By iamalwayshappy, history, 6 weeks ago, Is there anyone who gave zio 2022 held on 5 december? Can we discuss it's solutions here?? Comments (10)
 » There's already a discussion thread on CodeChef.Quoting the questions from there: Q1) Given a binary string (represented by B and G for boys and girls in question), find the least number of switches (switching position of B and G from any index counts as 2) that maximizes the number of adjacent characters that are not the same. Q2) Ways to partition an array (consisting of 1,2,3,…,n) into less than or equal to k sub arrays such that for any two sub arrays A and B, there are no elements a,c ∈ A and b,d ∈ B such that a
•  » » IDK but for ,first my ans are (we have to make max pair of the opposite genders and max no. of pair would be min(no.of boys,no. of girls) 4 2 4
•  » » » That's cause you would have considered that one girl and one boy can be a part of only one pair.For example: in GBG there can be 2 pairs: GB and BG but if you consider that one boy can be a part of only one pair then you will be forming only 1 pair either GB or BG.
•  » » » » Do you know 2nd testcase of first question?
•  » » » » » GGGBBBBBBBG
•  » » » » » » MY answer : (GB)(GB)(GB)BBB(BG)
•  » » » » » » » According to your answer, there will be 6 pairs 1 2 3 4 5 6 7 8 9 10 11 G B G B G B B B B B G 1.(1,2) = GB 2.(2,3) = BG 3.(3,4) = GB 4.(4,5) = BG 5.(5,6) = GB 6.(10,11) = BG So, totally 6 pairs such that adjacent elements are not of the same type.But another which performs better is BGBBGBGBBGB 1 2 3 4 5 6 7 8 9 10 11 B G B B G B G B B G B 1. (1,2) = BG 2. (2,3) = GB 3. (4,5) = BG 4. (5,6) = GB 5. (6,7) = BG 6. (7,8) = GB 7. (9,10) = BG 8. (10,11) = GB Hence, giving us 8 pairs such that adjacent elements are not of the same type.The swaps to achieve the order would be:GGGBBBBBBBG => GGGBBBBBBGB => BGGBGBBBBGB => BGBBGBGBBGB After changing positions of 6 students you achieve this arrangement.
 » I am getting different answers for ques 2? Is there anyone else who are getting different answers for ques 2.
•  » » 6 weeks ago, # ^ | ← Rev. 2 →   My Python code for Q2 gives the following answers:A) 46B) 42C) 16796Though my approach is just brute force (and definitely not the intended one, but nevertheless it verifies the answer)
 » Any idea about cutoff for class 9?