Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
22 views

Python Coding Questions 1-100 (1)

The document contains a list of 19 Python coding questions, each with a description, examples, and constraints. The questions cover various topics such as string manipulation, array operations, linked lists, and mathematical problems. Each question is designed to test different programming skills and concepts in Python.

Uploaded by

prasannay528
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Python Coding Questions 1-100 (1)

The document contains a list of 19 Python coding questions, each with a description, examples, and constraints. The questions cover various topics such as string manipulation, array operations, linked lists, and mathematical problems. Each question is designed to test different programming skills and concepts in Python.

Uploaded by

prasannay528
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Python Coding Questions

S.No Description
1. Given a string s, return the longest
Palindromic substring in s.

Example 1:
Input: s = "babad"
Output: "bab"
Explanation: "aba" is also a valid answer.

Example 2:
Input: s = "cbbd"
Output: "bb"

Constraints:
1 <= s.length <= 1000
s consist of only digits and English letters.

2. Given an array of integers nums and an integer target, return indices of the
two numbers such that they add up to target.

You may assume that each input would have exactly one solution, and you
may not use the same element twice.

You can return the answer in any order.

Example 1:
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].

Example 2:
Input: nums = [3,2,4], target = 6
Output: [1,2]
Example 3:
Input: nums = [3,3], target = 6
Output: [0,1]

Constraints:
2 <= nums.length <= 10^4
-10^9 <= nums[i] <= 10^9
-10^9 <= target <= 10^9
Only one valid answer exists.
3. You are given the heads of two sorted linked lists list1 and list2.
Merge the two lists into one sorted list. The list should be made by splicing
together the nodes of the first two lists.

Return the head of the merged linked list.

Example 1:
Input: list1 = [1,2,4], list2 = [1,3,4]
Output: [1,1,2,3,4,4]

Example 2:
Input: list1 = [], list2 = []
Output: []

Example 3:
Input: list1 = [], list2 = [0]
Output: [0]

Constraints:
The number of nodes in both lists is in the range [0, 50].
-100 <= Node.val <= 100
Both list1 and list2 are sorted in non-decreasing order.

4. Given an integer array nums sorted in non-decreasing order, remove the


duplicates in-place such that each unique element appears only once.
The relative order of the elements should be kept the same. Then return the
number of unique elements in nums.

Consider the number of unique elements of nums to be k, to get accepted,


you need to do the following things:

Change the array nums such that the first k elements of nums contain the
unique elements in the order they were present in nums initially. The
remaining elements of nums are not important as well as the size of nums.
Return k.

Example 1:
Input: nums = [1,1,2]
Output: 2, nums = [1,2,_]
Explanation: Your function should return k = 2, with the first two elements of
nums being 1 and 2 respectively.
It does not matter what you leave beyond the returned k (hence they are
underscores).
Example 2:
Input: nums = [0,0,1,1,1,2,2,3,3,4]
Output: 5, nums = [0,1,2,3,4,_,_,_,_,_]
Explanation: Your function should return k = 5, with the first five elements of
nums being 0, 1, 2, 3, and 4 respectively.
It does not matter what you leave beyond the returned k (hence they are
underscores).

Constraints:
1 <= nums.length <= 3 * 10^4
-100 <= nums[i] <= 100
nums is sorted in non-decreasing order.

5. Roman numerals are represented by seven different


symbols: I, V, X, L, C, D and M.
Symbol Value
I 1
V 5
X 10
L 50
C 100
D 500
M 1000
For example, 2 is written as II in Roman numeral, just two ones added
together. 12 is written as XII, which is simply X + II. The number 27 is written
as XXVII, which is XX + V + II.

Roman numerals are usually written largest to smallest from left to right.
However, the numeral for four is not IIII. Instead, the number four is written
as IV. Because the one is before the five we subtract it making four. The
same principle applies to the number nine, which is written as IX. There are
six instances where subtraction is used:
I can be placed before V (5) and X (10) to make 4 and 9.
X can be placed before L (50) and C (100) to make 40 and 90.
C can be placed before D (500) and M (1000) to make 400 and 900.
Given a roman numeral, convert it to an integer.

Example 1:
Input: s = "III"
Output: 3
Explanation: III = 3.
Example 2:
Input: s = "LVIII"
Output: 58
Explanation: L = 50, V= 5, III = 3.

Example 3:
Input: s = "MCMXCIV"
Output: 1994
Explanation: M = 1000, CM = 900, XC = 90 and IV = 4.

Constraints:
1 <= s.length <= 15
s contains only the characters ('I', 'V', 'X', 'L', 'C', 'D', 'M').
It is guaranteed that s is a valid roman numeral in the range [1, 3999].

6. Given an integer x, return true if x is a palindrome, and false otherwise.

Example 1:
Input: x = 121
Output: true
Explanation: 121 reads as 121 from left to right and from right to left.
Example 2:
Input: x = -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes
121-. Therefore it is not a palindrome.
Example 3:
Input: x = 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.

Constraints:
-2^31 <= x <= 2^31 - 1

7. Given a string s consisting of words and spaces, return the length of


the last word in the string.
A word is a maximal substring consisting of non-space characters only.

Example 1:
Input: s = "Hello World"
Output: 5
Explanation: The last word is "World" with length 5.
Example 2:
Input: s = " fly me to the moon "
Output: 4
Explanation: The last word is "moon" with length 4.
Example 3:
Input: s = "luffy is still joyboy"
Output: 6
Explanation: The last word is "joyboy" with length 6.

Constraints:
1 <= s.length <= 10^4
s consists of only English letters and spaces ' '.
There will be at least one word in s.

8. A phrase is a palindrome if, after converting all uppercase letters into


lowercase letters and removing all non-alphanumeric characters, it reads the
same forward and backward. Alphanumeric characters include letters and
numbers.
Given a string s, return true if it is a palindrome, or false otherwise.

Example 1:
Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.
Example 2:
Input: s = "race a car"
Output: false
Explanation: "raceacar" is not a palindrome.
Example 3:
Input: s = " "
Output: true
Explanation: s is an empty string "" after removing non-alphanumeric
characters.
Since an empty string reads the same forward and backward, it is a
palindrome.

Constraints:
1 <= s.length <= 2 * 10^5
s consists only of printable ASCII characters.

9. Given an integer numRows, return the first numRows of Pascal's triangle.


Example 1:
Input: numRows = 5
Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
Example 2:
Input: numRows = 1
Output: [[1]]

Constraints:
1 <= numRows <= 30

10. Given an integer rowIndex, return the rowIndexth (0-indexed) row of


the Pascal's triangle.

Example 1:
Input: rowIndex = 3
Output: [1,3,3,1]
Example 2:
Input: rowIndex = 0
Output: [1]
Example 3:
Input: rowIndex = 1
Output: [1,1]

Constraints:
0 <= rowIndex <= 33

11. Given a non-empty array of integers nums, every element


appears twice except for one. Find that single one.
You must implement a solution with a linear runtime complexity and
use only constant extra space.

Example 1:
Input: nums = [2,2,1]
Output: 1
Example 2:
Input: nums = [4,1,2,1,2]
Output: 4
Example 3:
Input: nums = [1]
Output: 1

Constraints:
1 <= nums.length <= 3 * 10^4
-3 * 10^4 <= nums[i] <= 3 * 10^4
Each element in the array appears twice except for one element which
appears only once.

12. Given two strings needle and haystack, return the index of the first
occurrence of needle in haystack, or -1 if needle is not part of haystack.

Example 1:
Input: haystack = "sadbutsad", needle = "sad"
Output: 0
Explanation: "sad" occurs at index 0 and 6.
The first occurrence is at index 0, so we return 0.
Example 2:
Input: haystack = "PythonCode", needle = "Pythoc"
Output: -1
Explanation: "Pythoc" did not occur in "PythonCode", so we return -1.

Constraints:
1 <= haystack.length, needle.length <= 10^4
haystack and needle consist of only lowercase English characters.
13. Given a sorted array of distinct integers and a target value, return the index
if the target is found. If not, return the index where it would be if it were
inserted in order.
You must write an algorithm with O(log n) runtime complexity.

Example 1:
Input: nums = [1,3,5,6], target = 5
Output: 2
Example 2:
Input: nums = [1,3,5,6], target = 2
Output: 1
Example 3:
Input: nums = [1,3,5,6], target = 7
Output: 4

Constraints:
1 <= nums.length <= 10^4
-10^4 <= nums[i] <= 10^4
nums contains distinct values sorted in ascending order.
-10^4 <= target <= 10^4

14. Write a function to find the longest common prefix string amongst an array
of strings.
If there is no common prefix, return an empty string "".

Example 1:
Input: strs = ["flower","flow","flight"]
Output: "fl"
Example 2:
Input: strs = ["dog","racecar","car"]
Output: ""
Explanation: There is no common prefix among the input strings.

Constraints:
1 <= strs.length <= 200
0 <= strs[i].length <= 200
strs[i] consists of only lowercase English letters.

15. Given an integer n, return true if it is a power of two. Otherwise,


return false.
An integer n is a power of two, if there exists an integer x such that n == 2x.

Example 1:
Input: n = 1
Output: true
Explanation: 2^0 = 1
Example 2:
Input: n = 16
Output: true
Explanation: 2^4 = 16
Example 3:
Input: n = 3
Output: false

Constraints:
-2^31 <= n <= 2^31 - 1

16. Given two strings s and t, return true if t is an anagram of s,


and false otherwise.

An Anagram is a word or phrase formed by rearranging the letters of a


different word or phrase, typically using all the original letters exactly once.

Example 1:
Input: s = "anagram", t = "nagaram"
Output: true
Example 2:
Input: s = "rat", t = "car"
Output: false

Constraints:
1 <= s.length, t.length <= 5 * 10^4
s and t consist of lowercase English letters.

17. Given an integer array nums, return the third distinct maximum number in
this array. If the third maximum does not exist, return
the maximum number.

Example 1:
Input: nums = [3,2,1]
Output: 1
Explanation:
The first distinct maximum is 3.
The second distinct maximum is 2.
The third distinct maximum is 1.
Example 2:
Input: nums = [1,2]
Output: 2
Explanation:
The first distinct maximum is 2.
The second distinct maximum is 1.
The third distinct maximum does not exist, so the maximum (2) is returned
instead.
Example 3:
Input: nums = [2,2,3,1]
Output: 1
Explanation:
The first distinct maximum is 3.
The second distinct maximum is 2 (both 2's are counted together since they
have the same value).
The third distinct maximum is 1.

Constraints:
1 <= nums.length <= 10^4
-2^31 <= nums[i] <= 2^31 - 1

18. Given two non-negative integers, num1 and num2 represented as string,
return the sum of num1 and num2 as a string.

You must solve the problem without using any built-in library for handling
large integers (such as BigInteger). You must also not convert the inputs to
integers directly.

Example 1:
Input: num1 = "11", num2 = "123"
Output: "134"
Example 2:
Input: num1 = "456", num2 = "77"
Output: "533"
Example 3:
Input: num1 = "0", num2 = "0"
Output: "0"

Constraints:
1 <= num1.length, num2.length <= 10^4
num1 and num2 consist of only digits.
num1 and num2 don't have any leading zeros except for the zero itself.

19. Given a string s containing just the characters '(', ')', '{', '}', '[' and ']',
determine if the input string is valid.
An input string is valid if:
Open brackets must be closed by the same type of brackets.
Open brackets must be closed in the correct order.
Every close bracket has a corresponding open bracket of the same type.

Example 1:
Input: s = "()"
Output: true
Example 2:
Input: s = "()[]{}"
Output: true
Example 3:
Input: s = "(]"
Output: false

Constraints:
1 <= s.length <= 10^4
s consists of parentheses only '()[]{}'.

20. Given a string s, check if it can be constructed by taking a substring of it and


appending multiple copies of the substring together.

Example 1:
Input: s = "abab"
Output: true
Explanation: It is the substring "ab" twice.
Example 2:
Input: s = "aba"
Output: false
Example 3:
Input: s = "abcabcabcabc"
Output: true
Explanation: It is the substring "abc" four times or the substring "abcabc"
twice.

Constraints:
1 <= s.length <= 10^4
s consists of lowercase English letters.

21. Given a list of numbers, you have to sort them in non decreasing order.
Input Format
The first line contains a single integer N, denoting the number of integers in
the list.
The next N lines contain a single integer each, denoting the elements of the
list.
Output Format
Output N lines, containing one integer each, in non-decreasing order.
Constraints
1≤N≤10^6
0≤0≤ elements of the list ≤10^6≤10^6

Input :5 5 3 6 7 1
Output :1 3 5 6 7
22. Recently, Ravi visited his doctor. The doctor advised Chef to drink at
least 2000 ml of water each day.
Ravi drank X ml of water today. Determine if Ravi followed the doctor's
advice or not.
Input Format
The first line contains a single integer T — the number of test cases. Then
the test cases follow.
The first and only line of each test case contains one integer X — the amount
of water Ravi drank today.
Output Format
For each test case, output YES if Ravi followed the doctor's advice of drinking
at least 2000 ml of water. Otherwise, output NO.
You may print each character of the string in uppercase or lowercase (for
example, the strings YES, yEs, yes, and yeS will all be treated as identical).
Constraints
1≤T≤2000
1≤X≤4000
Input : Output:
3 YES
2999 NO
1450 YES
2000
23. Sita and Geetha are playing with dice. In one turn, both of them roll their
dice at once.
They consider a turn to be good if the sum of the numbers on their dice is
greater than 6.
Given that in a particular turn Sita and Geetha got X and Y on their
respective dice, find whether the turn was good.
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
Each test case contains two space-separated integers X and Y — the
numbers Sita and Geetha got on their respective dice.
Output Format
For each test case, output on a new line, YES, if the turn was good
and NO otherwise.
Each character of the output may be printed in either uppercase or
lowercase. That is, the strings NO, no, nO, and No will be treated as
equivalent.
Constraints
1≤T≤100
1≤X,Y≤6

Input : 4 Output:
14 NO
34 YES
42 NO
26 YES
24. Harsh was recently gifted a book consisting of N pages. Each page contains
exactly M words printed on it. As he was bored, he decided to count the
number of words in the book.
Help Harsh find the total number of words in the book.
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
Each test case consists of two space-separated integers on a single
line, N and M — the number of pages and the number of words on each
page, respectively.
Output Format
For each test case, output on a new line, the total number of words in the
book.
Constraints
1≤T≤100
1≤N≤100
1≤M≤100

Input :4 Output:
11 1
42 8
24 8
95 42 3990

25. Chef is fond of burgers and decided to make as many burgers as possible.
Chef has A patties and B buns. To make 1 burger, Chef needs 1 patty
and 1 bun.
Find the maximum number of burgers that Chef can make.
Input Format
The first line of input will contain an integer T — the number of test cases.
The description of T test cases follows.
The first and only line of each test case contains two space-separated
integers A and B, the number of patties and buns respectively.
Output Format
For each test case, output the maximum number of burgers that Chef can
make.
Constraints
1≤T≤1000
1≤A,B≤105

Input: 4 Output:
22 2
23 2
32 2
23 17 17
26. Sunil aims to be the richest person in Iceland by his new restaurant
franchise. Currently, his assets are worth A billion dollars and have no
liabilities. He aims to increase his assets by X billion dollars per year.
Also, all the richest people in Iceland are not planning to grow and maintain
their current worth.
To be the richest person in Iceland, he needs to be worth at least B billion
dollars. How many years will it take Sunil to reach his goal if his value
increases by X billion dollars each year?

Input
The first line contains an integer T, the number of test cases. Then the test
cases follow.
Each test case contains a single line of input, three integers A, B, X.

Output
For each test case, output in a single line the answer to the problem.

Constraints
1≤T≤21 000
100≤A<B≤200
1≤X≤50
X divides B−A
Input : 3 Output:
100 200 10 10
111 199 11 8
190 200 10 1
27. Chef will have N guests in his house today. He wants to serve at least one
dish to each of the N guests. Chef can make two types of dishes. He needs
one fruit and one vegetable to make the first type of dish and one vegetable
and one fish to make the second type of dish. Now Chef
has A fruits, B vegetables, and C fishes in his house. Can he prepare at
least N dishes in total?
Input Format
First line will contain T, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, four integers N,A,B,C.
Output Format
For each test case, print "YES" if Chef can prepare at least N dishes,
otherwise print "NO". Print the output without quotes.
Constraints
1≤T≤100
1≤N,A,B,C≤100

Input : 4 Output:
2121 YES
3222 NO
4263 YES
3131 NO

28. You are given two integers N and K. You may perform the following
operation any number of times (including zero): change N to N−K, i.e.
subtract K from N. Find the smallest non-negative integer value of N you can
obtain this way.
Input
The first line of the input contains a single integer T denoting the number of
test cases. The description of T test cases follows.
The first and only line of each test case contains two space-separated
integers N and K.
Output
For each test case, print a single line containing one integer — the smallest
value you can get.
Constraints
1≤T≤10^5
1≤N≤10^9
0≤K≤10^9

Input : 3 Output:
52 1
44 0
25 2
29. Alice and Bob are playing a game of Blobby Volley. In this game, in each
turn, one player is the server and the other player is the receiver. Initially,
Alice is the server, and Bob is the receiver.

If the server wins the point in this turn, their score increases by 1, and they
remain as the server for the next turn.

But if the receiver wins the point in this turn, their score does not increase.
But they become the server in the next turn.

In other words, your score increases only when you win a point when you
are the server.

Please see the Sample Inputs and Explanation for more detailed explanation.

They start with a score of 00 each, and play N turns. The winner of each of
those hands is given to you as a string consisting of 'A's and 'B's. 'A' denoting
that Alice won that point, and 'B' denoting that Bob won that point. Your job
is the find the score of both of them after the N turns.
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
Each test case consists of two lines of input.
The first line of each test case contains one integer N — the number of
turns.
The line contains a string S of length N.
If the ith character of this string is 'A', then Alice won that point.
If the ith character of this string is 'B', then Bob won that point.
Output Format
For each test case, output on a new line, two space-separated integers -
Alice's final score, and Bob's final score.
Constraints
1≤T≤1000
1≤N≤1000
Length of ∣S∣ = N
S consists only of the characters 'A' and 'B'.
Input: 4 Output:
3 30
AAA 03
4 11
BBBB 00
5
ABABB
5
BABAB

30. John has a string S with him. John is happy if the string contains a contiguous
substring of length strictly greater than 22 in which all its characters are
vowels.

Determine whether John is happy or not.


Note that, in english alphabet, vowels are a, e, i, o, and u.
Input Format
First line will contain T, number of test cases. Then the test cases follow.
Each test case contains of a single line of input, a string S.
Output Format
For each test case, if John is happy, print HAPPY else print SAD.
You may print each character of the string in uppercase or lowercase (for
example, the strings hAppY, Happy, haPpY, and HAPPY will all be treated as
identical).
Constraints
1≤T≤1000
3≤∣S∣≤1000, where ∣S∣ is the length of S.
S will only contain lowercase English letters.

Input: 4 Output:
Aeiou Happy
Abxy Sad
Aebcdefghij Sad
Abcdeeafg Happy
31. You are given a positive integer . Print a numerical triangle of height like the
one below:
1
22
333
4444
55555
......
Can you do it using only arithmetic operations, a single for loop and print
statement?
Use no more than two lines. The first line (the for statement) is already
written for you. You have to complete the print statement.
Note: Using anything related to strings will give a score of .
Input Format
A single line containing integer, .
Constraints
1<=N<=9
Output Format
Print lines as explained above.
Sample Input
5

Sample Output
1
22
333
4444

32. You are given a positive integer .


Your task is to print a palindromic triangle of size .
For example, a palindromic triangle of size is:
1
121
12321
1234321
123454321
You can't take more than two lines. The first line (a for-statement) is already
written for you.
You have to complete the code using exactly one print statement.
Note:Using anything related to strings will give a score of .
Using more than one for-statement will give a score of .
Input Format
A single line of input containing the integer .
Constraints
0<N<10
Output Format
Print the palindromic triangle of size as explained above.
Sample Input
5
Sample Output
1
121
12321
1234321
123454321

33. The provided code stub will read in a dictionary containing key/value pairs of
name:[marks] for a list of students. Print the average of the marks array for
the student name provided, showing 2 places after the decimal.
Input Format
The first line contains the integer , N the number of students' records. The
next lines contain the names and marks obtained by a student, each value
separated by a space. The final line contains query_name, the name of a
student to query.
Constraints
2<=n<=10
0<=marks[I]<=100
Length of marks arrays=3

Output Format
Print one line: The average of the marks obtained by the particular student
correct to 2 decimal places.
Sample Input 0
3
Krishna 67 68 69
Arjun 70 98 63
Malika 52 56 60
Malika
Sample Output 0
56.00

Sample Input 1
2
Harsh 25 26.5 28
Anurag 26 28 30
Harsh
Sample Output 1
26.50

34. There is an array of integers. There are also 2 disjoint sets, A and , B each
containing integers. You like all the integers in set A and dislike all the
integers in set B . Your initial happiness is 0. For each integer in the array, if I
belongs to A, you add i to your happiness. If ,I belongs to B you add -1 to
your happiness. Otherwise, your happiness does not change. Output your
final happiness at the end.
Note: Since A and B are sets, they have no repeated elements. However, the
array might contain duplicate elements.
Constraints
1<=n<=10^5
1<=m<=10^5
1<=Any integer in the input<=10^9
Input Format
The first line contains integers n and m separated by a space.
The second line contains n integers, the elements of the array.
The third and fourth lines contain m integers, A and B, respectively.
Output Format
Output a single integer, your total happiness.
Sample Input
32
153
31
57
Sample Output
1

35. You are given a string and your task is to swap cases. In other words, convert
all lowercase letters to uppercase letters and vice versa.
Function Description
Complete the swap_case function in the editor below.
swap_case has the following parameters:
string s: the string to modify
Returns
string: the modified string
Input Format
A single line containing a string s.
Constraints
0<len(s)<=1000
Sample Input 0
NriiT PresEnts CodinG ClaSses
Sample Output 0
nRIIt pRESeNTS cODINg cLAsSES
36. Consider the following:
A string,s , of length n where s=C0C1….Cn-1.
An integer,k , where k is a factor of n.
We can split s into n/k substrings where each subtring, ti , consists of a
contiguous block of characters in s. Then, use each ti to create
string ui such that:
The characters in ui are a subsequence of the characters in ti.
Any repeat occurrence of a character is removed from the string such that
each character in ui occurs exactly once. In other words, if the character at
some index j in ti occurs at a previous index < j in ti, then do not include the
character in string ui .
Given s and k , print n/k lines where each line denotes string .
Example
s=’AAABCADDE’
K=3
There are three substrings of length 3 to consider: 'AAA', 'BCA' and 'DDE'.
The first substring is all 'A' characters, so u1=’A’. The second substring has all
distinct characters, so u2=’BCA’ . The third substring has different
characters, so u3=’DE’ . Note that a subsequence maintains the original
order of characters encountered. The order of characters in each
subsequence shown is important.
Function Description
Complete the merge_the_tools function in the editor below.
merge_the_tools has the following parameters:
string s: the string to analyze
int k: the size of substrings to analyze
Prints
Print each subsequence on a new line. There will be n/k of them. No return
value is expected.
Input Format
The first line contains a single string, s.
The second line contains an integer,k , the length of each substring.
Constraints
1<=n<=10^4, where n is the length of s
1<=k<=n
It is guaranteed that n is a multiple of k .
Sample Input
STDIN Function
----- --------
AABCAAADA s = 'AABCAAADA'
3 k=3
Sample Output
AB
CA
AD

37. You are given a string S and width w.


Your task is to wrap the string into a paragraph of width w.
Input Format
The first line contains a string, S.
The second line contains the width, w.

Constraints
0 < len(S) < 1000
0 < w < len(S)

Output Format
Print the text wrapped paragraph.
Sample Input 0
ABCDEFGHIJKLIMNOQRSTUVWXYZ
4

Sample Output 0
ABCD
EFGH
IJKL
IMNO
QRST
UVWX
YZ

38. You are given a complex z. Your task is to convert it to polar coordinates.
Input Format
A single line containing the complex number z. Note: complex() function can
be used in python to convert the input as a complex number.
Constraints
Given number is a valid complex number.
Output Format
Output two lines:
The first line should contain the value of r.
The second line should contain the value of q.
Sample Input
1+2j
Sample Output
2.23606797749979
1.1071487177940904

39. Mr. Vincent works in a door mat manufacturing company. One day, he
designed a new door mat with the following specifications:
Mat size must be N X M. (N is an odd natural number, and M is 3 times N.)
The design should have ‘WELCOME’ written in the center.
The design pattern should only use |, . and – characters.
Sample Designs
Size: 7 x 21
---------.|.---------
------.|..|..|.------
---.|..|..|..|..|.---
-------WELCOME-------
---.|..|..|..|..|.---
------.|..|..|.------
---------.|.---------

Size: 11 x 33
---------------.|.---------------
------------.|..|..|.------------
---------.|..|..|..|..|.---------
------.|..|..|..|..|..|..|.------
---.|..|..|..|..|..|..|..|..|.---
-------------WELCOME-------------
---.|..|..|..|..|..|..|..|..|.---
------.|..|..|..|..|..|..|.------
---------.|..|..|..|..|.---------
------------.|..|..|.------------
---------------.|.---------------
Input Format
A single line containing the space separated values of N and M.
Constraints
5 < N < 101
15 < M < 303
Output Format
Output the design pattern.
Sample Input
9 27

Sample Output
------------ . | . ------------
--------- . | . . | . . | . ---------
------ . | . . | . . | . . | . . |. ------
--- . | . . | . . | . . | . . | . . | . . | . ---
----------WELCOME----------
--- . | . . | . . | . . | . . | . . | . . | . ---
------ . | . . | . . | . . | . . | . ------
--------- . | . . |. . | . ---------
------------ . | . ------------

40. You are given a two lists A and B. Your task is to compute their cartesian
product A x B.
Example
A = [1, 2]
B = [3, 4]

A x B = [(1, 3), (1, 4), (2, 3), (2, 4)]


Note: A and B are sorted lists, and the cartesian product’s tuples should be
output in sorted order.
Input Format
The first line contains the space separated elements of list A.
The second line contains the space separated elements of list B.
Both lists have no duplicate integer elements.
Constraints
0<A<B
0 < B < 30
Output Format
Output the space separated tuples of the cartesian product.
Sample Input
12
34
Sample Output
(1, 3) (1, 4) (2, 3) (2, 4)

41. Raghu is a shoe shop owner. His shop has X number of shoes.
He has a list containing the size of each shoe he has in his shop.
There are N number of customers who are willing to pay xi amount of
money only if they get the shoe of their desired size.
Your task is to compute how much money Raghu earned.
Input Format
The first line contains X, the number of shoes.
The second line contains the space separated list of all the shoe sizes in the
shop.
The third line contains N, the number of customers.
The next N lines contain the space separated values of the shoe size desired
by the customer and xi, the price of the shoe.
Constraints
0 < X < 10^3
0 < N <= 10^3
20 < xi < 100
2 < shoe size < 20
Output Format
Print the amount of money earned by Raghu.
Sample Input
10
2 3 4 5 6 8 7 6 5 18
6
6 55
6 45
6 55
4 40
18 60
10 50
Sample Output
200

42. There is a horizontal row of n cubes. The length of each cube is given. You
need to create a new vertical pile of cubes. The new pile should follow these
directions: if cube[i] is on top of cube[j] then sideLength|j| => sideLength|i|.

When stacking the cubes, you can only pick up either the leftmost or the
rightmost cube each time. Print Yes if it is possible to stack the cubes.
Otherwise, print No.
Example
blocks = [1, 2, 3, 8, 7]
Result: No

After choosing the rightmost element, 7, choose the leftmost element, 1.


After than, the choices are 2 and 8. These are both larger than the top block
of size 1.
blocks = [1, 2, 3, 7, 8]
Result: Yes

Choose blocks from right to left in order to successfully stack the blocks.
Input Format
The first line contains a single integer T, the number of test cases.
For each test case, there are 2 lines.
The first line of each test case contains n, the number of cubes.
The second line contains n space separated integers, denoting
the sideLengths of each cube in that order.

Constraints
1 <= T <= 5
1 <= n <= 10^5
1 <= sideLength < 2^31

Output Format
For each test case, output a single line containing either Yes or No.
Sample Input
STDIN Function
----- --------
2 T=2
6 blocks[] size n = 6
432134 blocks = [4, 3, 2, 1, 3, 4]
3 blocks[] size n = 3
132 blocks = [1, 3, 2]

Sample Output
Yes
No

43. You are given a function f(X) = X2. You are also given K lists. The ith list
consists of Ni elements.

You have to pick one element from each list so that the value from the
equation below is maximized:
S = (f(X1) + f(X2) + . . . + f(Xk) % M

Xi denotes the element picked from the ith list . Find the maximized
value Smax obtained. % denotes the modulo operator.
Note that you need to take exactly one element from each list, not
necessarily the largest element. You add the squares of the chosen elements
and perform the modulo operation. The maximum value that you can
obtain, will be the answer to the problem.

Input Format
The first line contains 2 space separated integers K and M.
The next K lines each contains an integer Ni, denoting the number of
elements in the ith list, followed by Ni space separated integers denoting the
elements in the list.

Constraints
1 <= K <= 7
1 <= M <= 1000
1 <= Ni <= 7
1 <= Magnitude of elements in list <= 109

Output Format
Output a single integer denoting the value Smax.

Sample Input
3 1000
254
3789
5 5 7 8 9 10
Sample Output
206

44. Mr. Anant Asankhya is the manager at the INFINITE hotel. The hotel has an
infinite amount of rooms.

One fine day, a finite number of tourists come to stay at the hotel.
The tourists consist of:
→ A Captain.
→ An unknown group of families consisting of K members per group
where K ≠ 1.

The Captain was given a separate room, and the rest were given one room
per group.

Mr. Anant has an unordered list of randomly arranged room entries. The list
consists of the room numbers for all of the tourists. The room numbers will
appear K times per group except for the Captain’s room.

Mr. Anant needs you to help him find the Captain’s room number.
The total number of tourists or the total number of groups of families is not
known to you.

You only know the value of K and the room number list.

Input Format
The first line consists of an integer, K, the size of each group.
The second line contains the unordered elements of the room number list.

Constraints
1 < K < 1000

Output Format
Output the Captain’s room number.

Sample Input
5
1236544253616532412514368431562

Sample Output
8

45. You are given a set A and n other sets.


Your job is to find whether set A is a strict superset of each of the N sets.
Print True, if A is a strict superset of each of the N sets. Otherwise,
print False.

A strict superset has at least one element that does not exist in its subset.

Example
Set ([1 , 3, 4]) is a strict superset of set ([1 , 3]).
Set ([1 , 3, 4]) is not a strict superset of set ([1 , 3, 4]).
Set ([1 , 3, 4]) is not a strict superset of set ([1 , 3, 5]).

Input Format
The first line contains the space separated elements of set A.
The second line contains integer n, the number of other sets.
The next n lines contains the space separated elements of the other sets.

Constraints
0 < len(set(A)) < 50^1
0 < N < 2^1
0 < len(otherSets) < 10^1

Output Format
Print True if set A is a strict superset of all other N sets. Otherwise,
print False.
Sample Input 0
1 2 3 4 5 6 7 8 9 10 11 12 23 45 84 78
2
12345
100 11 12

Sample Output 0
False

46. You are given a spreadsheet that contains a list of N athletes and their
details (such as age, height, weight and so on). You are required to sort the
data based on the Kth attribute and print the final resulting table. Follow the
example given below for better understanding.
Note that K is indexed from 0 to M – 1, where M is the number of attributes.

Note: If two attributes are the same for different rows, for example, if two
atheletes are of the same age, print the row that appeared first in the input.
Input Format
The first line contains N and M separated by a space.
The next N lines each contain M elements.
The last line contains K.

Constraints
1 <= N, M <= 1000
0 <= K < M
Each element <= 1000

Output Format
Print the N lines of the sorted table. Each line should contain the space
separated elements. Check the sample below for clarity.

Sample Input 0
53
10 2 5
710
999
1 23 12
659
1

Sample Output 0
710
10 2 5
659
999
1 23 12
47. You are given a string N.
Your task is to verify that N is a floating point number.
In this task, a valid float number must satisfy all of the following
requirements:
->Number can start with +, - or . symbol.

For example:
✔+4.50
✔-1.0
✔.5
✔-.7
✔+.4
✖ -+4.5
->Number must contain at least 1 decimal value.

For example:
✖ 12.
✔12.0
->Number must have exactly one . symbol.
->Number must not give any exceptions when converted using float(N).

Input Format
The first line contains an integer T, the number of test cases.
The next T line(s) contains a string N.
Constraints
0 < T < 10

Output Format
Output True or False for each test case.

Sample Input 0
4
4.0O0
-1.00
+4.54
SomeRandomStuff

Sample Output 0
False
True
True
False

48. The National University conducts an examination of N students in X subjects.


Your task is to compute the average scores of each student.
Average Score = Sum of Scores obtained in all subjects by a student / Total
number of students

The format for the general mark sheet is:


Student ID → ___1_____2_____3_____4_____5__
Subject 1 | 89 90 78 93 80
Subject 2 | 90 91 85 88 86
Subject 3 | 91 92 83 89 90.5
|______________________________
Average 90 91 82 90 85.5

Input Format
The first line contains N and X separated by a space.
The next X lines contains the space separated marks obtained by students in
a particular subject.

Output Format
Print the averages of all students on separate lines.
The averages must be correct up to 1 decimal place.

Sample Input
53
89 90 78 93 80
90 91 85 88 86
91 92 83 89 90.5

Sample Output
90.0
91.0
82.0
90.0
85.5

49. You are given a string S.


S contains alphanumeric characters only.
Your task is to sort the string in the following manner:
All sorted lowercase letters are ahead of uppercase letters.
All sorted uppercase letters are ahead of digits.
All sorted odd digits are ahead of sorted even digits.

Input Format
A single line of input contains the string S.

Constraints
0 < len(S) < 1000

Output Format
Output the sorted string S.
Sample Input
Sorting1234

Sample Output
ginortS1324

50. Rupal has a huge collection of country stamps. She decided to count the
total number of distinct country stamps in her collection. She asked for your
help. You pick the stamps one by one from a stack of N country stamps.
Find the total number of distinct country stamps.
Input Format
The first line contains an integer N, the total number of country stamps.
The next N lines contains the name of the country where the stamp is from.
Constraints
0 < N < 1000
Output Format
Output the total number of distinct country stamps on a single line.
Sample Input
7
UK
China
USA
France
New Zealand
UK
France
Sample Output
5

51. A newly opened multinational brand has decided to base their company logo
on the three most common characters in the company name. They are now
trying out various combinations of company names and logos based on this
condition. Given a string s , which is the company name in lowercase letters,
your task is to find the top three most common characters in the string.
Print the three most common characters along with their occurrence count.
Sort in descending order of occurrence count.
If the occurrence count is the same, sort the characters in alphabetical
order.
For example, according to the conditions described above,
GOOGLE would have it's logo with the letters G,O,E .
Input Format
A single line of input containing the string S.

Constraints
->3<len(S)<=10^4
->S has at least distinct characters
Output Format
Print the three most common characters along with their occurrence count
each on a separate line.
Sort output in descending order of occurrence count.
If the occurrence count is the same, sort the characters in alphabetical
order.

Sample Input 0
Aabbbccde

Sample Output 0
b3
a2
c2

52. You are given a string S. Suppose a character ‘c’ occurs consecutively X times
in the string. Replace these consecutive occurrences of the character 'c'
with (X,c) in the string.
For a better understanding of the problem, check the explanation.
Input Format
A single line of input consisting of the string S.
Output Format
A single line of output consisting of the modified string.
Constraints
All the characters of S denote integers between 0 and 9.
1<=|S|<=10^4
Sample Input
1222311
Sample Output
(1, 1) (3, 2) (1, 3) (2, 1)
Explanation
First, the character 1 occurs only once. It is replaced by (1,1). Then the
character 2 occurs three times, and it is replaced by (3,2) and so on.

53. You and Fredrick are good friends. Yesterday, Fredrick received N credit
cards from ABCD Bank. He wants to verify whether his credit card numbers
are valid or not. You happen to be great at regex so he is asking for your
help!
A valid credit card from ABCD Bank has the following characteristics:

► It must start with a 4,5 or 6 .


► It must contain exactly 16 digits.
► It must only consist of digits (0-9).
► It may have digits in groups of 4, separated by one hyphen "-".
► It must NOT use any other separator like ' ' , '_', etc.
► It must NOT have 4 or more consecutive repeated digits.
Examples:

Valid Credit Card Numbers


4253625879615786
4424424424442444
5122-2368-7954-3214

Invalid Credit Card Numbers


42536258796157867 #17 digits in card number → Invalid
4424444424442444 #Consecutive digits are repeating 4 or more times
→ Invalid
5122-2368-7954 - 3214 #Separators other than '-' are used → Invalid
44244x4424442444 #Contains non digit characters → Invalid
0525362587961578 #Doesn't start with 4, 5 or 6 → Invalid

Input Format
The first line of input contains an integer .
The next lines contain credit card numbers.

Constraints
0 < N < 100

Output Format
Print 'Valid' if the credit card number is valid. Otherwise, print 'Invalid'. Do
not print the quotes.
Sample Input
6
4123456789123456
5123-4567-8912-3456
61234-567-8912-3456
4123356789123456
5133-3367-8912-3456
5123 - 3567 - 8912 - 3456

Sample Output
Valid
Valid
Invalid
Valid
Invalid
Invalid

54. You are the manager of a supermarket.


You have a list of items together with their prices that consumers bought on
a particular day.
Your task is to print each item_name and net_price in order of its first
occurrence.
item_name = Name of the item.
net_price = Quantity of the item sold multiplied by the price of each item.

Input Format
The first line contains the number of items, .
The next lines contains the item's name and price, separated by a space.
Constraints
0 < N <=100

Output Format
Print the item_name and net_price in order of its first occurrence.
Sample Input
9
BANANA FRIES 12
POTATO CHIPS 30
APPLE JUICE 10
CANDY 5
APPLE JUICE 10
CANDY 5
CANDY 5
CANDY 5
POTATO CHIPS 30

Sample Output
BANANA FRIES 12
POTATO CHIPS 60
APPLE JUICE 20
CANDY 20

55. you are given two complex numbers, and you have to print the result of
their addition, subtraction, multiplication, division and modulus operations.
The real and imaginary precision part should be correct up to two decimal
places.
Input Format
One line of input: The real and imaginary part of a number separated by a
space.
Output Format
For two complex numbers C and D, the output should be in the following
sequence on separate lines:
-> C+D
->C-D
->C*D
->C/D
->mod( C )
->mod(D)
For complex numbers with non-zero real (A) and (B) complex part, the
output should be in the following format: A+Bi

Replace the plus symbol (+) with a minus symbol (-) when B<0.
For complex numbers with a zero complex part i.e. real numbers, the output
should be:
A+0.00i
For complex numbers where the real part is zero and the complex part is
non-zero, the output should be:
0.00+Bi
Sample Input
21
56
Sample Output
7.00+7.00i
-3.00-5.00i
4.00+17.00i
0.26-0.11i
2.24+0.00i
7.81+0.00i

56. You are given a string, and you have to validate whether it's a valid Roman
numeral. If it is valid, print True. Otherwise, print False. Try to create a
regular expression for a valid Roman numeral.
Input Format
A single line of input containing a string of Roman characters.
Output Format
Output a single line containing True or False according to the instructions
above.
Constraints
The number will be between 1 and 3999 (both included).
Sample Input
CDXXI
Sample Output
True

57. You are given some input, and you are required to check whether they are
valid mobile numbers.
A valid mobile number is a ten digit number starting with a 7,8 or 9.
Input Format
The first line contains an integer N , the number of inputs.
N lines follow, each containing some string.
Constraints
1<= N <=10
2<=len(Number)<=15
Output Format
For every string listed, print "YES" if it is a valid mobile number and "NO" if it
is not on separate lines. Do not print the quotes.
Sample Input
2
9587456281
1252478965
Sample Output
YES
NO

58. You are given two sets, A and B.


Your job is to find whether set A is a subset of set B .

If set A is subset of set B , print True.


If set A is not a subset of set B , print False.
Input Format
The first line will contain the number of test cases, T .
The first line of each test case contains the number of elements in set A.
The second line of each test case contains the space separated elements of
set A.
The third line of each test case contains the number of elements in set B.
The fourth line of each test case contains the space separated elements of
set B.
Constraints
0 < T < 21
0 < Number of elements in each set < 1001

Output Format
Output True or False for each test case on separate lines.
Sample Input
3
5
12356
9
985632147
1
2
5
36541
7
1235689
3
982

Sample Output
True
False
False

59. You are given a list of N lowercase English letters. For a given integer K, you
can select any K indices (assume 1-based indexing) with a uniform
probability from the list.
Find the probability that at least one of the K indices selected will contain
the letter: 'a'.
Input Format
The input consists of three lines. The first line contains the integer N ,
denoting the length of the list. The next line consists of N space-separated
lowercase English letters, denoting the elements of the list.
The third and the last line of input contains the integer K, denoting the
number of indices to be selected.
Output Format
Output a single line consisting of the probability that at least one of the
K indices selected contains the letter:'a'.
Note: The answer must be correct up to 3 decimal places.
Constraints
1<=N<=10
I<=K<=N
All the letters in the list are lowercase English letters.
Sample Input
4
aacd
2
Sample Output
0.8333

60. ABCXYZ company has up to 100 employees.


The company decides to create a unique identification number (UID) for
each of its employees.
The company has assigned you the task of validating all the randomly
generated UIDs.
A valid UID must follow the rules below:
It must contain at least 2 uppercase English alphabet characters.
It must contain at least 3 digits (0 - 9).
It should only contain alphanumeric characters ( a-z ,A -Z & 0 -9 ).
No character should repeat.
There must be exactly 10 characters in a valid UID.

Input Format
The first line contains an integer , the number of test cases.
The next lines contains an employee's UID.
Output Format
For each test case, print 'Valid' if the UID is valid. Otherwise, print 'Invalid',
on separate lines. Do not print the quotation marks.
Sample Input
2
B1CD102354
B1CDEF2354

Sample Output
Invalid
Valid

61. Ravi belongs to a very rich family which owns many gold mines. Today, he
brought N gold coins and decided to form a triangle using these coins. Isn't it
strange?
Ravi has a unusual way of forming a triangle using gold coins, which is
described as follows:
He puts 1 coin in the 1st row.
then puts 2 coins in the 2nd row.
then puts 3 coins in the 3rd row.
and so on as shown in the given figure.

Ravi is interested in forming a triangle with maximum possible height using


at most N coins. Can you tell him the maximum possible height of the
triangle?
Input
The first line of input contains a single integer T denoting the number of test
cases.
The first and the only line of each test case contains an integer N denoting
the number of gold coins Chef has.
Output
For each test case, output a single line containing an integer corresponding
to the maximum possible height of the triangle that Chef can get.
Constraints
1 ≤ T ≤ 100
1 ≤ N ≤ 10^9

Sample Input : Sample Output:


3 2
3 2
5 3
7
62. You have a binary string S of length N. In one operation you can select a
substring of S and reverse it. For example, on reversing the substring
S[2,4] for S=11000, we change 11000→10010.
Find the minimum number of operations required to sort this binary string.
It can be proven that the string can always be sorted using the above
operation finite number of times.

Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
Each test case consists of 22 lines of input.
The first line of each test case contains a single integer N — the length of the
binary string.
The second line of each test case contains a binary string S of length N.
Output Format
For each test case, output on a new line — the minimum number of
operations required to sort the binary string.
Constraints
1≤T≤2⋅ 10^5
1≤N≤2⋅ 10^5
Sum of N over all test cases does not exceed 106106.
String S consists of only '00's and '11's.

Sample Input: Sample Output:


4 0
3 1
000 2
4 2
1001
4
1010
6
010101
63. A binary string is called alternating if no two adjacent characters of the
string are equal. Formally, a binary string T of length M is called alternating
if Ti !=Ti+1​ for each 1≤i<M.
For example, 0, 1, 01, 10, 101, 010, 1010 are alternating strings
while 11, 001, 1110 are not.
You are given a binary string S of length N. You would like to rearrange the
characters of S such that the length of the longest alternating
substring of S is maximum. Find this maximum value.
A binary string is a string that consists of characters 0 and 1. A string a is
a substring of a string b if a can be obtained from b by deletion of several
(possibly, zero or all) characters from the beginning and several (possibly,
zero or all) characters from the end.
Input Format
The first line of input contains an integer T, denoting the number of test
cases. The T test cases then follow:
The first line of each test case contains an integer N.
The second line of each test case contains the binary string S.
Output Format
For each test case, output the maximum possible length of the longest
alternating substring of S after rearrangement.

Constraints
1≤T≤10^4
1≤N≤10^5
S contains only the characters 0 and 1.
Sum of N over all test cases does not exceed 2⋅ 10^5.

Sample Input : Sample Output:


4 3
3 4
110 1
4 5
1010
4
0000
7
1101101

64. There are 33 hidden numbers A,B,C.


You somehow found out the values of min(A,B),min(B,C), and min(C,A).
Determine whether there exists any tuple (A,B,C) that satisfies the given
values of min(A,B),min(B,C),min(C,A).
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
The first and only line of each test case contains 33 space-separated integers
denoting the values of min(A,B),min(B,C), and min(C,A).
Output Format
For each test case, output YES if there exists any valid tuple (A,B,C),
and NO otherwise.
You can print each letter of the output in any case. For
example YES, yes, yEs will all be considered equivalent.
Constraints
1≤T≤1000
1≤min(A,B),min(B,C),min(C,A)≤10

Sample Input: Sample Output:


3 YES
555 NO
234 YES
224
65. Initially, John is at coordinate 00 on X-axis. For each i=1,2,…,N in order, John
does the following:
If John is at a non-negative coordinate, he moves i steps backward (i.e, his
position's coordinate decreases by i), otherwise he moves i steps forward
(i.e, his position's coordinate increases by i).
You are given the integer N. Find the final position of Chef on the X-axis
after N operations.
Input Format
The first line of input contains an integer T, denoting the number of test
cases. The T test cases then follow:
The first and only line of each test case contains an integer N.
Output Format
For each test case, output in a single line the final position of Chef on the X-
axis after N operations.
Constraints
1≤T≤10^5
1≤N≤10^9

Sample Input: Sample Output:


3 -1
1 1
2 -2
3
66. Ram wants to buy a new laptop. However, he is confused about which
laptop to buy out of 10 different laptops. He asks his N friends for their
recommendation. The ith friend recommends the Chef to buy
the Ai​ th laptop (1≤Ai≤10).
Ram will buy the laptop which is recommended by maximum number of
friends. Determine which laptop Chef buys.
Print CONFUSED if there are multiple laptops having maximum number of
recommendations.
Input Format
The first line contains a single integer T - the number of test cases. Then the
test cases follow.
The first line of each test case contains an integer N - the number of Chef's
friends.
The second line of each test case contains N space-separated
integers A1​ ,A2​ ,…,AN​ where Ai​ denotes the recommendation of
the ith friend.
Output Format
For each test case, output in a single line, the laptop which has
the maximum number of recommendations. Print CONFUSED if there are
multiple laptops having maximum number of recommendations.
You may print each character of CONFUSED in uppercase or lowercase (for
example, Confused, coNFused, CONFused will be considered identical).
Constraints
1≤T≤200
1≤N≤1000
1≤Ai​ ≤10

Sample Input: Sample Output:


4 4
5 6
44421 CONFUSED
7 CONFUSED
1234566
6
2 2 3 3 10 8
4
7788

67. Hari wants to store some important numerical data on his personal
computer. He is using a new data type that can store values only
from 00 till N both inclusive. If this data type receives a value greater
than N then it is cyclically converted to fit into the range 00 to N. For
Example:
Value N+1 will be stored as 00.
Value N+2 will be stored as 11.
and so on...
Given X, the value chef wants to store in this new data type. Determine what
will be the actual value in memory after storing X.
Input Format
First line will contain T, number of testcases. Then the testcases follow.
Each testcase contains a single line of input, two space separated
integers N,X - the maximum value a data type can store and the value Chef
wants to store in the data type respectively.
Output Format
For each testcase, output in a single line the value which will be actually
stored in memory.
Constraints
1≤T≤3000
1≤N≤50
0≤X≤50

Sample Input: Sample Output:


5 0
15 0 10
15 10 0
11 12 9
27 37 49
50 49
68. It is Anu’s birthday. You know that Anu's favourite number is X. You also
know that Anu loves averages. Therefore you decide it's best to gift
Chef 33 integers A1​ ,A2​ ,A3​ , such that:
The mean of A1​ ,A2​ and A3​ is X.
1≤A1​ ,A2​ ,A3​ ≤1000.
A1​ ,A2​ and A3​ are distinct.
Output any suitable A1​ ,A2​ and A3​ which you could gift to Anu.
As a reminder, the mean of three numbers P,Q,R is defined
as: mean(P,Q,R)=P+Q+R/3.
For
example, (2,3,5)=2+3+5/3=10/3=3.333ˉ, mean(2,2,5)=2+2+5/3​ =9/3​ =3.
Input Format
The first line of input contains a single integer T, denoting the number of
test cases. The description of T test cases follows.
The first and only line of each test case contains one integer X — Anu's
favourite number.
Output Format
For each test case, one line containing 3 space-separated integers —
A1​ ,A2​ , and A3​ , which satisfy the given conditions. If there are
multiple possible answers you may output any of them.
It can be shown that an answer always exists, under the given constraints.
Constraints
1≤T≤100
2≤X≤100

Sample Input: Sample Output:


3 135
3 168
5 357
5
69. There are N piles where the ith pile consists of Ai​ stones.
Zack and Ryan are playing a game taking alternate turns with Zack starting
first.
In his/her turn, a player can choose any non-empty pile and
remove exactly 11 stone from it.
The game ends when exactly 11 pile becomes empty. The player who made
the last move wins.
Determine the winner if both players play optimally.
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
Each test case consists of multiple lines of input.
The first line of each test case contains a single integer N denoting the
number of piles.
Next line contains N space-separated integers A1​ ,A2​ ,…,AN​ - denoting
the number of stones in each pile.
Output Format
For each test case, output Zack if Zack wins the game, otherwise
output Ryan.
Note that the output is case-insensitive i.e. ZACK, Zack, ZaCk, and zack are all
considered the same.
Constraints
1≤T≤1000
1≤N≤10^5
1≤Ai​ ≤10^9
Sum of N over all test cases does not exceed 2⋅ 1052⋅ 105.

Sample Input: Sample Output:


3 Ryan
2 Ryan
22 Zack
1
10
3
156
70. You are given a binary string S of length N. You can perform the following
operation on S:
Pick any set of indices such that no two picked indices are adjacent.
Flip the values at the picked indices (i.e. change 00 to 11 and 11 to 00).
For example, consider the string S=1101101.
If we pick the indices {1,3,6}, then after flipping the values at picked indices,
we will get 1101101-->0111111.
Note that we cannot pick the set {2,3,5} since 2 and 3 are adjacent indices.
Find the minimum number of operations required to convert all the
characters of S to 00.
Input Format
The first line contains a single integer T - the number of test cases. Then the
test cases follow.
The first line of each test case contains an integer N - the length of the
binary string S.
The second line of each test case contains a binary string S of length N.
Output Format
For each test case, output the minimum number of operations required to
convert all the characters of S to 00.

Constraints
1≤T≤100
1≤N≤100

Sample Input: Sample Output:


3 1
6 0
101001 2
5
00000
3
111

71. Swathi is fan of pairs and he likes all things that come in pairs. He even has a
doll collection in which the dolls come in pairs. One day while going through
his collection he found that there are odd number of dolls. Someone had
stolen a doll!!!
Help Swathi find which type of doll is missing..
Input
The first line contains an integer T, the number of test cases.
The first line of each test case contains an integer N, the number of dolls.
The next N lines are the types of dolls that are left.
Output
For each test case, display the type of doll that doesn't have a pair, in a new
line.
Constraints
1<=T<=10
1<=N<=100000 (10^5)
0<=type<=100000

Sample Input: Sample Output:


1 2
3
1
2
1

72. You are given an array A of size N. In one operation, you can do the
following:
Select indices i and j (I !=j) and set Ai​ =Aj​ .
Find the minimum number of operations required to make all elements of
the array equal.
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
Each test case consists of multiple lines of input.
The first line of each test case contains an integer N — the size of the array.
The next line contains N space-separated integers, denoting the array A.
Output Format
For each test case, output on a new line, the minimum number of
operations required to make all elements of the array equal.
Constraints
1≤T≤1000
1≤N≤2⋅ 10^5
1≤Ai​ ≤N
The sum of N over all test cases won't exceed 2⋅ 10^5.

Sample Input: Sample Output:


3 2
3 2
123 3
4
2231
4
3124
73. There are N different types of colours numbered from 11 to N. Chef
has Ai​ balls having colour i, (1≤i≤N).
Chef will arrange some boxes and put each ball in exactly one of those
boxes.
Find the minimum number of boxes Chef needs so that no box
contains two balls of same colour.
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases. The description of the test cases follows.
The first line of each test case contains a single integer N, denoting the
number of colors.
The second line of each test case contains N space-separated
integers A1​ ,A2​ ,…,AN​ — denoting the number of balls having colour i.
Output Format
For each test case, output the minimum number of boxes required so that
no box contains two balls of same colour.
Constraints
1≤T≤1000
2≤N≤100
1≤Ai​ ≤10^5

Sample Input : Sample Output:


3 8
2 15
85 4
3
5 10 15
4
4444
74. Devu has n weird friends. Its his birthday today, so they thought that this is
the best occasion for testing their friendship with him. They put up
conditions before Devu that they will break the friendship unless he gives
them a grand party on their chosen day. Formally, ith friend will break his
friendship if he does not receive a grand party on dith day.

Devu despite being as rich as Gatsby, is quite frugal and can give at most one
grand party daily. Also, he wants to invite only one person in a party. So he
just wonders what is the maximum number of friendships he can save.
Please help Devu in this tough task !!
Input
The first line of the input contains an integer T denoting the number of test
cases. The description of T test cases follows.
First line will contain a single integer denoting n.

Second line will contain n space separated integers where ith integer
corresponds to the day dith as given in the problem.
Output
Print a single line corresponding to the answer of the problem.
Constraints
1 ≤ T ≤ 10^4
1 ≤ n ≤ 50
1 ≤ di ≤ 100

Sample Input: Sample Output:


2 2
2 1
32
2
11
75. You are given an array A of length N. An element X is said to be dominant if
the frequency of X in A is strictly greater than the frequency of any other
element in the A.
For example, if A=[2,1,4,4,4] then 44 is a dominant element since its
frequency is higher than the frequency of any other element in A.
Find if there exists any dominant element in A.
Input Format
The first line of input contains a single integer T — the number of test cases.
Then the test cases follow.
The first line of each test case contains an integer N — the size of the
array A.
The second line of each test case contains N space-separated
integers A1​ ,A2​ ,…,AN​ denoting the array A.
Output Format
For each test case, output YES if there exists any dominant element in A.
Otherwise, output NO.
You may print each character of YES and NO in uppercase or lowercase (for
example, yes, yEs, Yes will be considered identical).

Constraints
1≤T≤500
1≤N≤1000
1≤Ai​ ≤N

Sample Input: Sample Output:


4 YES
5 NO
22222 YES
4 NO
1234
4
3321
6
112234
76. Siva wants to become fit for which he decided to walk to the office and
return home by walking. It is known that Siva's office is X km away from his
home.
If his office is open on 5 days in a week, find the number of kilometers Siva
travels through office trips in a week.
Input Format
First line will contain T, number of test cases. Then the test cases follow.
Each test case contains of a single line consisting of single integer X.
Output Format
For each test case, output the number of kilometers Siva travels through
office trips in a week.
Constraints
1≤T≤10
1≤X≤10

Sample Input: Sample Output:


4 10
1 30
3 70
7 100
10
77. Alex has X 5 rupee coins and Y 10 rupee coins. Alex goes to a shop to buy
chocolates for Chefina where each chocolate costs Z rupees. Find the
maximum number of chocolates that Alex can buy for Chefina.
Input Format
The first line contains a single integer T — the number of test cases. Then
the test cases follow.
The first and only line of each test case contains three integers X, Y and Z —
the number of 5 rupee coins, the number of 10 rupee coins and the cost of
each chocolate.
Output Format
For each test case, output the maximum number of chocolates that Alex can
buy for Chefina.
Constraints
1≤T≤100
1≤X,Y,Z≤1000

Sample Input: Sample Output:


4 15
10 10 10 3
318 16
813 0
4 4 1000
78. Arun has started working at the candy store. The store has 100 chocolates in
total.
Arun’s daily goal is to sell X chocolates. For each chocolate sold, he will
get 1 rupee. However, if Arun exceeds his daily goal, he gets 2 rupees per
chocolate for each extra chocolate.
If Arun sells Y chocolates in a day, find the total amount he made.
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
Each test case consists of two space-separated integers X and Y — the daily
goal of Arun, and the number of chocolates he actually sells.
Output Format
For each test case, output on a new line the total amount Arun made in a
day.
Constraints
1≤T≤100
1≤X,Y≤10

Sample Input: Sample Output:


4 1
31 5
55 10
47 4
23
79. Alice likes numbers which are even, and are a multiple of 7.
Bob likes numbers which are odd, and are a multiple of 9.
Alice, Bob, and Charlie find a number A.
If Alice likes A, Alice takes home the number.
If Bob likes A, Bob takes home the number.
If both Alice and Bob don't like the number, Charlie takes it home.
Given A, find who takes it home.
Note: You can prove that there is no integer A such that both Alice and Bob
like it.
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
Each test case consists of a single integer, A.

Output Format
For each test case, output on a new line who takes the number home -
"Alice", "Bob", or "Charlie".
You may print each character in uppercase or lowercase. For
example, Alice, alice, aLiCe, and ALICE are all considered identical.
Constraints
1≤T≤100
1≤A≤1000

Sample Input: Sample Output:


8 Charlie
7 Alice
14 Charlie
21 Charlie
18 Bob
27 Bob
63 Alice
126 Charlie
8
80. In Chefland, a valid phone number consists of 5 digits with no leading zeros.
For example, 98765,10000, and 71023 are valid phone numbers
while 04123,9231, and 872310 are not.
Chef went to a store and purchased N items, where the cost of each item
is X.
Find whether the total bill is equivalent to a valid phone number.
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
Each test case consists of two space-separated integers N and X — the
number of items Chef bought and the cost per item.
Output Format
For each test case, output on a new line, YES, if the total bill is equivalent to
a valid phone number and NO otherwise.
Each character of the output may be printed in either uppercase or
lowercase. That is, the strings NO, no, nO, and No will be treated as
equivalent.
Constraints
1≤T≤100
1≤N,X≤1000

Sample Input: Sample Output:


4 YES
25 785 NO
402 11 YES
100 100 NO
333 333

81. Kiran's phone has a total storage of S MB. Also, Chef has 2 apps already
installed on his phone which occupy X MB and Y MB respectively.
He wants to install another app on his phone whose memory requirement
is Z MB. For this, he might have to delete the apps already installed on his
phone. Determine the minimum number of apps he has to delete from his
phone so that he has enough memory to install the third app.
Input Format
The first line contains a single integer T — the number of test cases. Then
the test cases follow.
The first and only line of each test case contains four integers S,X,Y and Z —
the total memory of Kiran's phone, the memory occupied by the two already
installed apps and the memory required by the third app.
Output Format
For each test case, output the minimum number of apps Chef has to delete
from his phone so that he can install the third app.
Constraints
1≤T≤1000
1≤S≤500
1≤X≤Y≤S
X+Y≤S
Z≤S

Sample Input: Sample Output:


4 0
10 1 2 3 1
9451 2
15 5 10 15 1
100 20 30 75
82. It is the World Cup Finals. Surya only finds a match interesting if the skill
difference of the competing teams is less than or equal to D.
Given that the skills of the teams competing in the final
are X and Y respectively, determine whether Surya will find the game
interesting or not.
Input Format
The first line of input will contain a single integer T, denoting the number of
testcases. The description of T testcases follows.
Each testcase consists of a single line of input containing three space-
separated integers X, Y, and D — the skill levels of the teams and the
maximum skill difference.
Output Format
For each testcase, output "YES" if Chef will find the game interesting, else
output "NO" (without the quotes). The checker is case-insensitive, so "YeS"
and "nO" etc. are also acceptable.
Constraints
1≤T≤2000
1≤X,Y≤100
0≤D≤100

Sample Input: Sample Output:


3 YES
534 NO
531 YES
550
83. After the phenomenal success of the 36th Chamber of Shaolin, San Te has
decided to start 37th Chamber of Shaolin. The aim this time is to equip
women with shaolin self-defence techniques.

The only condition for a woman to be eligible for the special training is that
she must be between 1010 and 6060 years of age, inclusive of
both 1010 and 6060.

Given the ages of N women in his village, please help San Te find out how
many of them are eligible for the special training.
Input Format
The first line of input contains a single integer T, denoting the number of
test cases. The description of T test cases follows.
The first line of each test case contains a single integer N, the number of
women.
The second line of each test case contains N space-separated
integers A1​ ,A2​ ,...,AN​ , the ages of the women.
Output Format
For each test case, output in a single line the number of women eligible for
self-defence training.
Constraints
1≤T≤20
1≤N≤100
1≤Ai​ ≤100

Sample Input: Sample Output:


3 2
3 2
15 23 65 1
3
15 62 16
2
35 9
84. There are two problems in a contest.
Problem A is worth 500 points at the start of the contest.
Problem B is worth 1000 points at the start of the contest.

Once the contest starts, after each minute:


Maximum points of Problem A reduce by 2 points .
Maximum points of Problem B reduce by 4 points.

It is known that Ajay requires X minutes to solve Problem A correctly


and Y minutes to solve Problem B correctly.

Find the maximum number of points Ajay can score if he optimally decides
the order of attempting both the problems.
Input Format
First line will contain T, number of test cases. Then the test cases follow.
Each test case contains of a single line of input, two integers X and Y - the
time required to solve problems A and B in minutes respectively.

Output Format
For each test case, output in a single line, the maximum number of points
Chef can score if he optimally decides the order of attempting both the
problems.
Constraints
1≤T≤1000
1≤X,Y≤100

Sample Input: Sample Output:


4 1360
10 20 1292
8 40 1380
15 15 1400
20 10
85. JK is struggling to pass a certain college course.
The test has a total of N questions, each question carries 3 marks for a
correct answer and −1 for an incorrect answer. JK is a risk-averse person so
he decided to attempt all the questions. It is known that JK got X questions
correct and the rest of them incorrect. For JK to pass the course he must
score at least P marks.
Will JK be able to pass the exam or not?
Input Format
First line will contain T, number of testcases. Then the testcases follow.
Each testcase contains of a single line of input, three integers N,X,P.
Output Format
For each test case output "PASS" if Chef passes the exam and "FAIL" if JK
fails the exam.
You may print each character of the string in uppercase or lowercase (for
example, the strings "pASs", "pass", "Pass" and "PASS" will all be treated as
identical).
Constraints
1≤T≤1000
1≤N≤100
0≤X≤N
0≤P≤3⋅ N

Sample Input: Sample Ouput:


3 PASS
523 FAIL
524 FAIL
400
86. You are given the sizes of angles of a simple quadrilateral (in
degrees) A, B, C and D, in some order along its perimeter. Determine
whether the quadrilateral is cyclic.

Note: A quadrilateral is cyclic if and only if the sum of opposite angles


is 180∘ .
Input
The first line of the input contains a single integer T denoting the number of
test cases. The description of T test cases follows.
The first and only line of each test case contains four space-separated
integers A, B, C and D.
Output
Print a single line containing the string "YES" if the given quadrilateral is
cyclic or "NO" if it is not (without quotes).
You may print each character of the string in uppercase or lowercase (for
example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as
identical).
Constraints
1≤T≤10^4
1≤A,B,C,D≤357
A+B+C+D=360

Sample Input: Sample Ouput:


3 NO
10 20 30 300 YES
10 20 170 160 NO
179 1 179 1
87. RK bought N items from a shop. Although it is hard to carry all these items in
hand, so Chef has to buy some polybags to store these items.
1 polybag can contain at most 10 items. What is the minimum number of
polybags needed by RK?
Input Format
The first line will contain an integer T - number of test cases. Then the test
cases follow.
The first and only line of each test case contains an integer N - the number
of items bought by RK.
Output Format
For each test case, output the minimum number of polybags required.
Constraints
1≤T≤1000
1≤N≤1000

Sample Input: Sample Output:


3 2
20 3
24 10
99
88. Given n (n is even), determine the number of black cells in
an n×n chessboard.
Input Format
The only line of the input contains a single integer n.
Output Format
Output the number of black cells in an n×n chessboard.
Constraints
2≤n≤100
n is even

Sample Input: Sample Output:


8 32
89. Ram has fallen in love with Sita, and wants to buy N gifts for her. On
reaching the gift shop, Ram got to know the following two things:
The cost of each gift is 1 coin.
On the purchase of every 4th gift, Ram gets the 5th gift free of cost.
What is the minimum number of coins that Ram will require in order to
come out of the shop carrying N gifts?
Input Format
The first line of input will contain an integer T — the number of test cases.
The description of T test cases follows.
The first and only line of each test case contains an integer N, the number of
gifts in the shop.
Output Format
For each test case, output on a new line the minimum number of coins that
Chef will require to obtain all N gifts.
Constraints
1≤T≤1000
1≤N≤10^9

Sample Input: Sample Output:


2 4
5 4
4
90. In Chefland, denominations less than rupees 10 have stopped and now
rupees 10 is the smallest denomination.
Suppose KK goes to buy some item with cost not a multiple of 10, then, he
will be charged the cost that is the nearest multiple of 10.
If the cost is equally distant from two nearest multiples of 1010, then the
cost is rounded up.
For example, 35,38,40,44 are all rounded to 40.
KK purchased an item having cost X (X≤100) and gave a bill of rupees 100.
How much amount will he get back?
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
Each test case consists of a single integer X, the cost of the item.
Output Format
For each test case, output the amount returned to Chef.
Constraints
1≤T≤100
1≤X≤100

Sample Input: Sample Output:


4 60
35 50
54 20
80 90
12
91. Chef has 3 numbers A,B and C.
Chef wonders if it is possible to choose exactly two numbers out of the three
numbers such that their sum is odd.
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
Each test case consists of three integers A,B,C.
Output Format
For each test case, output YES if you can choose exactly two numbers with
odd sum, NO otherwise.
The output is case-insensitive. Thus, the strings YES, yes, yeS, and Yes are all
considered the same.
Constraints
1≤T≤100
1≤A,B,C≤10

Sample Input: Sample Output:


4 YES
123 NO
846 NO
339 YES
786
92. James has a square-shaped chart paper with the side length equal to N. He
wants to cut out K×K squares from this chart paper.
Find the maximum number of K×K squares he can cut from the entire chart
paper.
Note that, some part of the chart paper might not be a included in
any K×K cutout square.
Input Format
The first line contains a single integer T — the number of test cases. Then
the test cases follow.
The first and only line of each test case contains two space-separated
integers N and K — the side length of the entire chart paper and the side
length of the cutout squares.
Output Format
For each test case, output on a new line the maximum number
of K×K squares James can cut from the entire chart paper.
Constraints
1≤T≤1000
1≤K≤N≤1000

Sample Input: Sample Output:


3 25
51 1
22 4
52
93. Roy is confused whether to go out and eat at the restaurant or order food
online.
The online order costs N rupees while the cost of eating at the restaurant
is M rupees.
However, Roy has a discount coupon with which he can avail flat 10% off on
his online order.
Find the cheaper option for Roy to eat, i.e., whether to order food online or
eat at the restaurant.
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
Each test case consists of two space-separated integers N and M, the cost of
ordering online and eating at the restaurant respectively.
Output Format
For each test case, output on a new line:
ONLINE, if Roy gets a better deal in online ordering,
DINING if Roy gets a better deal in eating at the restaurant,
EITHER if both deals cost the same.
You may print each character in uppercase or lowercase, For example, the
strings Online, online, ONLINE, and onLiNe are all considered identical.
Constraints
1≤T≤1000
1≤N,M≤1000

Sample Input: Sample Output:


4 ONLINE
500 500 DINING
500 400 DINING
25 22 EITHER
100 90
94. There are 2 stores in Chefland and both sell the same product. The first store
sells the product for 100 rupees whereas the second store sells it
for 200 rupees.
It is the holiday season and both stores have announced a special discount.
The first store is providing a discount of A percent on its product and the
second store is providing a discount of B percent on its product.
Tony is wondering which store is selling the product at a cheaper price after
the discount has been applied. Can you help him identify the better deal?
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
Each test case consists of a single line of input containing two space-
separated integers A and B denoting the discount provided by the first and
second store respectively.
Output Format
For each test case, output FIRST if the first store is cheaper, SECOND if the
second store is cheaper, and BOTH if both the stores are selling the product
for the same price after discount.
The checker is case-insensitive so answers like FiRsT, first, and FIRST would
be considered the same.
Constraints
1≤T≤1000
1≤A,B≤100

Sample Input: Sample output:


4 FIRST
5 20 SECOND
10 60 FIRST
77 BOTH
10 55
95. Hackerman wants to know who is the better player between Bob and Alice
with the help of a game.
The game proceeds as follows:
First, Alice throws a die and gets the number A
Then, Bob throws a die and gets the number B
Alice wins the game if the sum on the dice is a prime number; and Bob wins
otherwise.

Given A and B, determine who wins the game.


Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
The first and only line of each test case contains two space-separated
integers A and B.
Output Format
For each test case, output on a new line the winner of the
game: Alice or Bob.
Each letter of the output may be printed in either uppercase or lowercase,
i.e, Alice, ALICE, AlIce and aLIcE will all be considered equivalent.

Constraints
1≤T≤36
1≤A≤6
1≤B≤6

Sample Input: Sample Output:


3 Alice
21 Alice
11 Bob
22

96. Arun has two variables X and Y. He wants to find out whether the variables
satisfy the equation:
X^2+4.Y^2=4.X^2.Y
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
Each test case consists of two integers X and Y, as mentioned in statement.
Output Format
For each test case, output YES if the variables X and Y satisfy the given
equation, NO otherwise.
You may print each character in uppercase or lowercase. For
example, Yes, YES, yes, and YeS are all considered the same.
Constraints
1≤T≤1000
1≤X≤10^9
1≤Y≤10^18

Sample Input: Sample Output:


5 YES
22 NO
44 NO
36 YES
8 32 YES
200000000 20000000000000000
97. Rushitote went to a programming contest to distribute apples and oranges
to the contestants.
He has N apples and M oranges, which need to be divided equally amongst
the contestants. Find the maximum possible number of contestants such
that:
Every contestant gets an equal number of apples; and
Every contestant gets an equal number of oranges.
Note that every fruit with Rushitote must be distributed, there cannot be
any left over.
For example, 2 apples and 4 oranges can be distributed equally to two
contestants, where each one receives 1 apple and 2 oranges.
However, 2 apples and 5 oranges can only be distributed equally to one
contestant.
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
The first and only line of each test case contains two space-separated
integers N and M — the number of apples and oranges, respectively.
Output Format
For each test case, output on a new line the answer: the maximum number
of contestants such that everyone receives an equal number of apples and
an equal number of oranges.
Constraints
1≤T≤1000
1≤N,M≤10^9

Sample Input: Sample Output:


3 1
15 2
24 2
46
98. Luigi has an array A of N positive integers. He wants to make all elements of
the array equal.
In one move, he can:
Choose an index i (1≤i≤N) and divide the element Ai​ by any one of
its divisors.
In other words, he can choose a positive integer X such that X∣Ai​ and
set Ai​ :=XAi​ ​ .
Find the minimum number of moves required to make all the elements of
the array equal.
Input Format
The first line of input will contain a single integer T, denoting the number of
test cases.
Each test case consists of two lines of input.
The first line of each test case contains N, the size of array A.
The second line of each test case contains N space-separated integers, the
elements of array A.
Output Format
For each test case, output on a new line, the minimum number of moves
required to make all elements of the array equal.
Constraints
1≤T≤1000
1≤N≤3000
1≤Ai​ ≤10^9

Sample Input: Sample Output:


4 1
2 0
11 22 2
5 4
38 38 38 38 38
4
4 4 16 8
4
11 13 17 19
99. Raghu has an array A of length N.
An index i is called strong if we can change the gcd of the whole array just by
changing the value of Ai​ .
Determine the number of strong indices in the array.
Input Format
First line will contain T, number of test cases. Then the test cases follow.
First line of each test case contains an integer N denoting the size of the
array A.
Second line contains N space separated integers A1​ ,A2​ ,…,AN​ -
denoting the array A.
Output Format
For each test case, output the number of strong indices in the array.
Constraints
1≤T≤5⋅ 10^4
2≤N≤3⋅ 10^5
1≤Ai​ ≤10^9
Sum of N over all test cases do not exceed 3⋅ 105.

Sample Input: Sample Output:


3 3
3 0
5 10 20 4
4
3 5 7 11
4
2222
100. Given an integer N, help Chef in finding an N-
digit odd positive integerodd positive integer X such that X is divisible
by 3 but not by 9.
Note:Note: There should not be any leading zeroes in X. In other
words, 003 is not a valid 3-digit odd positive integer.
Input Format
The first line of input contains a single integer T, denoting the number of
testcases. The description of the T testcases follows.
The first and only line of each test case contains a single integer N, denoting
the number of digits in X.
Output Format
For each testcase, output a single line containing an N-digit odd positive
integer X in decimal number system, such that X is divisible by 3 but not
by 9.
Constraints
1≤T≤500
1≤N≤10^4
The sum of N over all test cases does not exceed 105
Sample Input: Sample Output:
3 3
1 15
2 123
3

You might also like