Web Programming - Code Test
Web Programming - Code Test
https://www.spritle.com/
0
Web Programming - Code Test
https://www.spritle.com/
ONE
Input:
The first line of input contains an integer T denoting the number of test cases.
For each test case first line contains N
(size of array). The subsequent line
contains N-1 array elements.
Output:
Constraints:
1 ≤ T ≤ 200
1 ≤ N ≤ 107
1 ≤ C[i] ≤ 107
Example:
Input:
2
5
1
Web Programming - Code Test
https://www.spritle.com/
1 2 3 5
10
1 2 3 4 5 6 7 8 10
Output:
4
9
Explanation:
2
Web Programming - Code Test
https://www.spritle.com/
TWO
Given an input stream of N integers. The task is to insert these numbers into a
new stream and find the median of the stream formed by each insertion of X
to the new stream.
Input:
The first line of input contains an integer N denoting the number of elements
in the stream. Then the next N lines contains integer x denoting the number
to be inserted into the stream.
Output:
For each element added to the stream print the floor of the new median in a
new line.
Constraints:
Example:
Input:
4
3
Web Programming - Code Test
https://www.spritle.com/
5
15
1
3
Output:
5
10
5
4
Explanation:
Testcase 1:
4
Web Programming - Code Test
https://www.spritle.com/
THREE
Given a String of length S, reverse the whole string without reversing the
individual words in it. Words are separated by dots.
Input:
The first line contains T denoting the number of testcases. T testcases follow.
Each case contains a string S containing characters.
Output:
For each test case, in a new line, output a single line containing the reversed
String.
Constraints:
Example:
Input:
2
i.would.liket.to.work.with.spritle
clean.code
Output:
spritle.with.work.to.like.would.i
code.clean
5
Web Programming - Code Test
https://www.spritle.com/
Four
Input:
The first line of input contains an integer T, denoting the no of test
cases. Then T test cases follow. Each test case contains a string str.
Output:
For each test case, print a new line containing the resulting string.
Constraints:
1<=T<=100
1<=Length of string<=50
Example:
Input:
2
sppritlleewoorkwiith
Acaaabbbacdddd
Output:
spritleworkwith
acac
6
Web Programming - Code Test
https://www.spritle.com/
FIVE
Given two strings a and b consisting of lowercase characters. The task is to
check whether two given strings are anagram of each other or not. An
anagram of a string is another string that contains same characters, only the
order of characters can be different. For example, “act” and “tac” are anagram
of each other.
Input:
The first line of input contains an integer T denoting the number of test cases.
Each test case consist of two strings in 'lowercase' only, in a single line.
Output:
Print "YES" without quotes if the two strings are anagram else print "NO".
Constraints:
1 ≤ T ≤ 300
1 ≤ |s| ≤ 1016
Example:
Input:
2
geeksforgeeks forgeeksgeeks
allergy allergic
Output:
YES
7
Web Programming - Code Test
https://www.spritle.com/
NO
Explanation:
Testcase 1: Both the string have same characters with same frequency. So,
both are anagrams.
Testcase 2: Characters in both the strings are not same, so they are not
anagrams.
8
Web Programming - Code Test
https://www.spritle.com/
SIX
Given a array of N strings, find the longest common prefix among all strings
present in the array.
Input:
The first line of the input contains an integer T which denotes the number of
test cases to follow. Each test case contains an integer N. Next line has space
separated N strings.
Output:
Print the longest common prefix as a string in the given array. If no such prefix
exists print "-1"(without quotes).
Constraints:
Example:
Input:
2
4
geeksforgeeks geeks geek geezer
9
Web Programming - Code Test
https://www.spritle.com/
3
apple ape april
Output:
gee
ap
Explanation:
Testcase 1: Longest common prefix in all the given string is gee.
10
Web Programming - Code Test
https://www.spritle.com/
SEVEN
Example:
Input:
5
7
Output:
*
* *
* * *
* * * *
* * * * *
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
11
Web Programming - Code Test
https://www.spritle.com/
EIGHT
Given a matrix m at[][] of size M *N. Traverse and print the matrix in spiral
form.
Input:
The first line of the input contains a single integer T, denoting the number of
test cases. Then T test cases follow. Each testcase has 2 lines. First line
contains M and N respectively separated by a space. Second line contains
M*N values separated by spaces.
Output:
Elements when travelled in Spiral form, will be displayed in a single line.
Constraints:
1 <= T <= 100
2 <= M,N <= 10
0 <= Ai <= 100
Example:
Input:
2
4 4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
3 4
1 2 3 4 5 6 7 8 9 10 11 12
Output:
1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10
1 2 3 4 8 12 11 10 9 5 6 7
12
Web Programming - Code Test
https://www.spritle.com/
13