Practice Questions Dated 1 June 2022

Problems:


Question 1:

Transmit a Message

Problem statement


Professor X has developed a new machine to transmit messages. The machine accepts a message in the form of a string of characters and transmits it to another machine of the same type at some other location. However, the machine has a certain bug. It can transmit only one type of character. As soon as it encounters a different type of character, the message recorded till that point is erased and the machine starts recording a new message beginning from that character.


Professor X wants to send the longest message possible to his friend. To do this, he can stop the machine at any point and transmit the message by pressing the send button. However, he can do this only when the machine is in the recording mode and not the erasing mode. He wants your help.

Given the input string, your task is to find the longest possible message that can be delivered by the machine. If there is more than one longest possible message, find the message which is nearer to the end of the string.



Example 1


Input


abb


Output


2


bb


Explanation


The acceptable string is abb, and the machine records 'a'. then encounters an unacceptable character 'b'. so the previous message is lost and the new message starts with 'b' and finally when it encounters the same character, the final message is 'bb'. Thus the output1 is 2 and output2 is 'bb'.


Example 2


Input


aabbddd


Output


3


ddd


Explanation


The acceptable string is aabbddd, the machine records 'a' then encounters another 'a' thus the message becomes 'aa'. After this, the machine encounters 'b', so the previous message is lost and the new message starts with 'b', and in the same manner, the final message is 'ddd'. Thus the output1 is 3 and output2 is 'ddd'.


Input format


The original string message.


Output format


The first output is an integer denoting the length of the longest possible message.


The second output is a string denoting the longest possible message.


Code constraints


1 <= string length <= 1000, and S contains only characters and no spaces.



Sample testcases
Input 1
abb
Output 1
2
bb
Input 2
aabbddd
Output 2
3
ddd





=========================================================================




Question 2:



Mars stone


Problem Statement


Rob has gone to Mars to collect some stones. The bag he is carrying can hold a maximum weight of M. There are M stones weighing from 1 to M in Mars. There are N stones on Mars that are similar to the ones on Earth. Find the number of stones he can bring from Mars such that none of them are similar to any stone on Earth.


Example1


Input


10


3


1 3 5


Output


2


Explanation


Rob collects one of the following stone weight sets: (2, 4), (2, 6), or (2, 8).


Example2


Input


14


4


4 6 8 9


Output


4


Explanation


Rob collects one of the following weight sets: (1, 2, 3, 7) or (1, 2, 3, 5)


Input format


input1: M, denoting the size of the bag and the number of different stone weights present on Mars.


input2: N, denoting the number of common stones on Earth and Mars.


input3: An N element array containing the list of the weights of the common stones.


Output format


Your function should return the maximum unique stones that can be collected from Mars.



Input 1
10
3
1 3 5
Output 1
2
Input 2
14
4
4 6 8 9
Output 2
4





For Solutions:


https://yashboss116.blogspot.com/2022/06/solutions-of-practice-questions-dated.html








"Thanks For Solving. 🤔🙋"


"Share Further To Enhance Knowledge. 😊"



Comments

Popular posts from this blog

Solutions Of Practice Questions Dated 01-06-2022

CODEFORCES SPY DETECTED ROUND 713

Maximum Winning Score Geeks For Geeks