TCS Ninja

☞ Given a string S and a character C, write a program to count the number of substrings of S that contains only the character C.
Sample Input
0110111
1
Sample Output
9

☞ A famous company is going to select a new Managing Director. All the eligible candidates are waiting in the meeting room. Everyone is seated in a random order linearly. Everyone are cunning and want's to become the Managing Director. If the founder of that company tell's a person name directly definitely that is going to become a serious problem. But the founder already have a person on his mind. But he was thinking for a creative idea to convey the same. Suddenly he notice a pattern follows and he find a way to tell who is the new MD.
He says "the MD of this company is the person who has the age greater than all the other people to his right side."
Write the program to find the new MD of that company where you are provided with the n persons age in order similar to their seating arrangement. In case if the founder couldn't find the next MD print, "The promotion stands cancelled".
Sample Input
7
56 53 52 58 51 56 57
Sample Output
4

☞ Robert is expert in strings where he challenges everyone to write a program for the below implementation.
Two strings and comprising of lower case English letters are compatible if they are equal or can be made equal by following this step any number of times:
Select a prefix from the string (possibly empty), and increase the alphabetical value of all the characters in the prefix by the same valid amount.
For example if the string is abc and we select the prefix ab then we can convert it to bcc by increasing the alphabetical value by 1. But if we select the prefix abc then we cannot increase the alphabetical value.
Your task is to determine if given strings are compatible.
Sample Input
abaca
cdbda
Sample Output
Yes

☞ Given an array arr[] of N integers arranged in a circular fashion. Your task is to find the maximum contiguous subarray sum.
Sample Input
3
7
8 -8 9 -9 10 -11 12
8
10 -3 -4 7 6 5 -4 -1
8
-1 40 -14 7 6 5 -4 -1
Sample Output
22
23
52

☞ Write a program to display the characters in prime position of a given string.
Sample Input
Computer
Sample Output
o m u e

☞ Given an unsorted array Arr[] and a number N. You need to write a program to find if there exists a pair of elements in the array whose difference is N. If the pair is found print 1 otherwise print -1.
Sample Input
2
6 78
5 20 3 2 5 80
5 45
90 70 20 80 50
Sample Output
1
-1

☞ Given an expression examine whether the pairs and the orders of '{', '}', '(', ')', '[', ']' are corret in expression. The program should print "Balanced" when you follow order in expression otherwise print "Not Balanced".
Sample Input1
{[()]}
Sample Output1
Balanced
Sample Input2
)([]{})
Sample Output2
Not Balanced

☞ Consider the below series:
1, 2, 1, 3, 2, 5, 3, 7, 5, 11, 8, 13, 13, 17, …
This series is a mixture of 2 series – all the odd terms in this series form a Fibonacci series and all the even terms are the prime numbers in ascending order.
Write a program to find the Nth term in this series.

☞ Read an array with positive integer elements and perform sorting operation.
  • If the array is sorted with more than one swap, print -1.
  • If the array is already in sorted, print 0.
  • If the array is sorted with one swap, print 1.
Sample Input1
4
1 2 2 4
Sample Output1
0
Sample Input2
5
1 10 3 4 3
Sample Output2
1

☞ Tahir and Mamta are working in a project in TCS. Tahir being a problem solver came up with an interesting problem for his friend Mamta.
Problem consists of a string of length N and contains only small case alphabets.
It will be followed by Q queries, in which each query will contain an integer P (1<=P<=N) denoting a position within the string.
Mamta’s task is to find the alphabet present at that location and determine the number of occurrence of same alphabet preceding the given location P. Mamta is busy with her office work. Therefore, she asked you to help her.
Constraints
1<=N<=500000
S consisting of small case alphabets
1<=Q<=10000
1<=P<=N
Sample Input:
9
abacsddaa
2
9
3
Sample Output:
3
1