1.

Given a string str and another string patt. Find the character in patt that is present at the minimum index in str. If no character of patt is present in str then print ‘No character present’.

Input:
The first line of input contains an integer T denoting the number of test cases. Then the description of T test cases follow. Each test case contains two strings str and patt respectively.

Output:
Output the character in patt that is present at the minimum index in str. Print "$" (without quotes) if no character of patt is present in str.

User Task:
The task is to complete the function printMinIndexChar() which finds the character in patt that is present at minimum index in str.

Constraints:
1 <= T <= 105
1 <= |str|, |patt| <= 105

Example:

Input:
2
mytat
set
adcffaet
onkl
Output:
e
$

Explanation:
Testcase 1:
 e is the character which is present in given patt "mytat" and is first found in str "set".

2.

Example Problem 1 : Range Minimum Query

We have an array arr[0 . . . n-1]. We need to efficiently find the minimum value from index L (query start) to R (query end) where 0 <= L <= R <= n-1. Consider a situation when there are many range queries. 
Example: 

Input:  arr[]   = {7, 2, 3, 0, 5, 10, 3, 12, 18};
        query[] = [0, 4], [4, 7], [7, 8]
Output: Minimum of [0, 4] is 0
        Minimum of [4, 7] is 3
        Minimum of [7, 8] is 12

The idea is to precompute minimum of all subarrays of size 2j where j varies from 0 to Log n. We make a table lookup[i][j] such that lookup[i][j] contains minimum of range starting from i and of size 2j. For example lookup[0][3] contains minimum of range [0, 7] (starting with 0 and of size 23)
How to fill this lookup or sparse table? 
The idea is simple, fill in a bottom-up manner using previously computed values. We compute ranges with current power of 2 using values of lower power of two. For example, to find a minimum of range [0, 7] (Range size is a power of 3), we can use the minimum of following two. 
a) Minimum of range [0, 3] (Range size is a power of 2) 
b) Minimum of range [4, 7] (Range size is a power of 2)
Based on above example, below is formula, 

// Minimum of single element subarrays is same
// as the only element.
lookup[i][0] = arr[i]

// If lookup[0][2] <=  lookup[4][2], 
// then lookup[0][3] = lookup[0][2]
If lookup[i][j-1] <= lookup[i+2j-1][j-1]
   lookup[i][j] = lookup[i][j-1]

// If lookup[0][2] >  lookup[4][2], 
// then lookup[0][3] = lookup[4][2]
Else 
   lookup[i][j] = lookup[i+2j-1][j-1]
3.

Given a sorted doubly linked list of distinct nodes(no two nodes have the same data) and a value x. Count triplets in the list that sum up to a given value x.

Examples:
 

4.
Given a doubly linked list and a position n. The task is to delete the node at the given position n from the beginning.
  1. Get the pointer to the node at position n by traversing the doubly linked list up to the nth node from the beginning.
  2. Delete the node using the pointer obtained in Step 1.
5.
Given a sorted doubly linked list and a value to insert, write a function to insert the value in sorted way.
Algorithm: 
Let input doubly linked list is sorted in increasing order. 
New node passed to the function contains data in the data part and previous and next link are set to NULL.
6.

Given a sequence of n integers, \((a_1, a_2,....a_n)\). You are asked to perform the following operation and return the obtained result.

For a given integer x calculate the value of the expression: \(\min_{i=1}^{j=n-x+1}(fun(a_i, a_{i+1},...,a_{i+x-1}))\)

\(fun(a_i, a_{i+1},...,a_{i+x-1})\) returns the value of the rightmost number with highest number of distinct prime factors.

In other words, if \(m_i = fun(a_i, a_{i+1},....a_{i+x-1})\), then you have to find the value of \(\min(m_i)\).

Input

The first line of input contains two integers, x and n.
Followed by n integers, \((a_{1}, a_{2},....a_{n})\).

Output

Print an integer denoting the value of the expression.

Constraints

\(1 \le n \le 10^6\)
\(1 \le x \le n\)
0 \le a_i \le 10^6

7.

Given, an array A containing N elements. Perform the following two queries on this given array:

0 L R - Print out the value of the required summation \(\sum_{j=L}^{R}\sum_{k=j+1}^{R}(A_j*A_k)\) .

1 X V - Change the value of the number at X^{th}position to V .

Note:
Indexing is 1 based.

Input format

  • The first line of the input contains two space-separated integers N and Q.
  • Next line contains N space separated integers of the given array A.
  • Following Q lines give description of each query.

Output format

Output the answer for each query type 0 L R in a separate line.

Constraints

  • \(1 \leq N, Q \leq 10^5\)
  • \(1 \leq A_{i}, V \leq 10^4\)
  • \(1 \leq L \leq R \leq N\)
  • 1 \leq X \leq N
8.

Given a String S , print the reverse of the string as output.

Example 1:

Input: S = "MYTAT"
Output: "TATYM" 
Explanation: Element at first is at last and
last is at first, second is at second last and
second last is at second position and so on .

Example 2:

Input: S = "ReversE"
Output: "EsreveR"
Explanation: "E" at first and "R" at last and
"e" at second last and "s" at second and
so on .


Your Task:  
You dont need to read input or print anything. Complete the function revStr() which takes S as input parameter and returns the reversed string .

Expected Time Complexity: O(|S|)
Expected Auxiliary Space: O(|S|)

Constraints:
1<= |S| <=1000

9.

Given a string S. The task is to convert characters of string to lowercase.

Example 1:

Input: S = "ABCddE"
Output: "abcdde"
Explanation: A, B, C and E are converted to
a, b, c and E thus all uppercase characters
of the string converted to lowercase letter.

Example 2:

Input: S = "LMNOppQQ"
Output: "lmnoppqq"
Explanation: L, M, N, O, and Q are
converted to l, m, n, o and q thus 
all uppercase characters of the
string converted to lowercase letter.

Your Task:  
You dont need to read input or print anything. Complete the function toLower() which takes S as input parameter and returns the converted string.

Expected Time Complexity:O(n)
Expected Auxiliary Space: O(1) 

Constraints:
1 <= |S| <= 1000

10.

Given an array of strings, return all groups of strings that are anagrams. The groups must be created in order of their appearance in the original array. Look at the sample case for clarification.


Example 1:

Input:
N = 5
words[] = {act,god,cat,dog,tac}
Output:
god dog
act cat tac
Explanation:
There are 2 groups of
anagrams "god", "dog" make group 1.
"act", "cat", "tac" make group 2.

Example 2:

Input:
N = 3
words[] = {no,on,is}
Output:
no on
is
Explanation:
There are 2 groups of
anagrams "no", "on" make group 1.
"is" makes group 2. 


Your Task:
The task is to complete the function Anagrams() that takes a list of strings as input and returns a list of groups such that each group consists of all the strings that are anagrams.


Expected Time Complexity: O(N*|S|*log|S|), where |S| is the length of the strings.
Expected Auxiliary Space: O(N*|S|), where |S| is the length of the strings.


Constraints:
1<=N<=100