Posts

Showing posts from July, 2021

Decode the message

Description Your friend sent you an encrypted message consisting of characters A, C, G and T only .You know the decoded message is the longest repetition in the sequence. That is a maximum-length substring containing only one kind of character. Can you decode it? Input Input Format The only input line contains a string of n characters. Constraints 1 <= n <= 10^6 Output Print one integer: the length of the longest repetition. Sample Input 1  ATTCGGGA Sample Output 1 3 Hint Sample Input 1 Explanation In the given string , substring GGG of length 3 is the longest.

Print V Pattern as given in Sample Input.

Description You need to print pattern as given in Sample Input. Note:- Make sure to check for spaces. In output, there is no spaces at end of each line. Input First line contains N. (1<= N <= 10) Output Print pattern for N. Sample Input 1  1 Sample Output 1 \/ Sample Input 2  4 Sample Output 2 \ / \ / \ / \/ Hint Self Explanatory

Count the number of subarrays

Description Given an array A with N positive integers. Count the number of subarrays of length greater than 1, such that the sum of the start and end elements of the subarray is even. Input First line: Single integer denoting the value of T - the number of test cases. For each test case: First line: Single integer denoting the value of N. Next line: N single space-separated integers denoting the elements of array A. Constraints: 1 <= T <= 100 1 <= N<= 100 Any array elements is not greater than 100. Output For each test case, print in a new line, a single integer denoting the number of subarrays. Sample Input 1  1 5 1 2 3 4 5 Sample Output 1 4 Hint Given test cases, Test 1: N = 5. A: 1 2 3 4 5. The following subarrays have an even sum of start and end elements : 1. 1 2 3 2. 1 2 3 4 5 3. 2 3 4 4. 3 4 5 Hence the answer is 4. Answer: . 

Social Networking for Everyone

Description You are designing a social networking website that makes everyone make friends in their neighborhood. But, the distance within which people can make friends depends on their age. If a person is of age less than 13, they can make friends within 1 Kms of their area, if the age of person is greater than or equal to 13 but less than 18, they can make friends within 5 Kms of their area, and if the age of the person is greater than or equal to  18 but less than 30, then they can make friends within 10 Kms of their area, else the person can make friends from anywhere. If the age of the person is less than 13 print "1 Kms", else if the age of the person is more than or equal to 13, and less than 18, then print "5 Kms", else if the age of the person is greater than or equal to 18 and less than 30, then print "10 Kms", else print "You can have friends from anywhere". Input The first and the only line of the input contains N, the age of the pers...

Verify Palindrome or Not

Description Given 2 strings of N length (equal length), when we concatenate these 2 strings check whether the final string so formed is a palindrome or not. Output "yes" if the final string so formed is a palindrome else "no" Note: String contains lowercase English alphabet e.g.: abc cba Upon concatenation the final string will be "abccba" , it is a palindrome , so output will be "yes" Input Input Format: First line of input contains the number N , denoting the length of each string Second line of input contains the string S1 Third line contains another string S2 Constraints: 1<=N<=500 Output Output "yes" or "no" Sample Input 1  3 abc def Sample Output 1 no Sample Input 2  4 abba abba Sample Output 2 yes

Alternate Palindrome

  Description Given a string of even length , we choose characters alternatively starting from front then back then front and so on and check whether the string so formed is a palindrome or not. A string is a palindrome if it reads same forwards and backwards. Note: String contains lowercase English alphabet, and it is 0-index based e.g.: "abab", string formed if we choose element at 0th index then last index then 1st and then second last and so on till we exhaust the string. string formed : "abba", it is a palindrome, so output will be "yes" Input Input Format: First line of input contains the number N , denoting the length of the string Second line of input contains the string. Constraints: 1<=N<=500 Output Output "yes" or "no" Sample Input 1  4 abab Sample Output 1 yes Sample Input 2  5 abcdef Sample Output 2 no Hint In Sample 1: N = 4 String: abab String formed after choosing characters in alternate way, like we choose , a-...

World Test Championship print the name of the teams which has more points

Description India & Australia just finished a Test Series, which was part of the inaugural world test championship. Now, you are given the points of the two teams, print the name of the teams which has more points. If the points of both the teams are same, the winner is the team which has played lesser number of games. If the number of matches played by the two teams is also same, then print " Play another game! ". Input The input consists of 4 lines where the first line consists, the first line indicates the points of the India, the second line consists the points of the Australia, the next line contains the matches played by India, and the final line contains the matches played by Australia. Constraints 1 < Points < 1500 1 < Matches <= 15 Output Print the name of the team which has more points, if the points of the two team are same, print the name of the team which has played lesser number of games, else print " Play another game! ". Sample Input ...

Birthday Chocolates Shopping

Description Your birthday is coming, and to celebrate it, you want to give chocolates to all the students of your class. There are M students in your class, and you have N rupees to spend on the chocolates. Now, you can buy  "Dairy Milk", "Shots" or "Eclairs". The cost of Dairy Milk is 5 Rs per chocolate, and the cost of Shots is 2 Rs per chocolate, and the cost of Eclairs is 1 Rs per chocolate. You only have N rupees saved from your pocket money, and you want to buy the most expensive chocolate possible for your classmates. Print "Dairy Milk", if you can buy M of them within N rupees, else if you can buy M Shots within N rupees, print "Shots", else if you can buy M eclairs within N rupees, print "Eclairs", else print "No Chocolates". Input The first line of input contains N, the amount of money you have. Next line contains M, the number of students in your class. Constraints 1 <= N <= 200 1 <= M <= 100 O...

Find the maximum number of times an odd number is continuously repeated in the array

Longest Repeated Odd Description You are given an array A of N integers. Your task is to find the maximum number of times an odd number is continuously repeated in the array. Input Input Format First line contains N which is the number of element present in the array. Second line contains N integers which are the values of array. Constraints N<100 Output Output Format Output one integer which the maximum number of times an odd number is repeated in array. Sample Input 1  12 1 1 1 1 2 2 2 2 2 1 1 1 Sample Output 1 4 Hint Sample 1 Explanation 1 is repeated 4 times from index 0 to index 3 => 4 times 2 is repeated 5 times from index 4 to index 8 => 5 times 1 is repeated 3 times from index 9 to index 11 => 3 times So, the output is 4 since 1 is odd.