Question Set 4
This is
question set 4. Another day another set.This set contains 3 questions from the famous CSES problems set.This set has some problems that new programmers must give a try. Happy Coding!
"while(!success)
keep trying”
You are
given a DNA sequence: a string consisting of characters A, C, G, and T. Your
task is to find the longest repetition in the sequence. This is a
maximum-length substring containing only one type of character. The only input
line contains a string of n characters. Print one integer: the length
of the longest repetition.
Constraints
- 1 ≤ n≤ 10^6
Example
Input: ATTCGGGA
Output: 3
Link to
the question- https://cses.fi/problemset/task/1069
Problem 2-Weird Algorithm (Easy)
Consider an algorithm that takes as input a positive integer n. If n is even, the algorithm divides it by two, and if n is odd, the algorithm multiplies it by three and adds one. The algorithm repeats this, until n is one. For example, the sequence for n=3 is as follows:
3→10→5→16→8→4→2→13→10→5→16→8→4→2→1
Your task is to simulate the execution of the algorithm for a given value
of n.The only input line contains an integer n.
Print a line that contains all values of n during the algorithm.
Constraints
- 1≤n≤10^6
Example
Input:3
Output:3 10 5 16 8 4 2 1
Link to
the question-
Problem 3-Missing Number(Easy)
You are given all numbers between except one. Your task is to find the missing number.
Print the missing number.
Constraints
Example
Input:n=5 arr=[2 3 1 5]
Output:4
Link to
the question-
Problem 4-Hard Sequence (Easy)
Chef decided to write an infinite sequence. Initially, he wrote , and then he started repeating the following process:
- Look at the last element written so far (the -th element if the sequence has length so far); let's denote it by
- If x does not occur anywhere earlier in the sequence, the next element in the sequence is .
- Otherwise, look at the previous occurrence of in the sequence, i.e. the -th element, where this element is equal to and all elements between the and -th are different from . The next element is , i.e. the distance between the last two occurrences of
The resulting sequence is : the second element is since occurs only once in the sequence , the third element is since the distance between the two occurrences of in the sequence is , the fourth element is since occurs only once in the sequence , and so on.
Chef has given you a task to perform. Consider the -th element of the sequence (denoted by ) and the first elements of the sequence. Find the number of occurrences of among these elements.
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first and only line of each test case contains a single integer
Constraints
- 1≤T≤128
- 1≤N≤128
Link to
the question-
Comments
Post a Comment