Programming Geek
Rated 4.7/5 based on 1446 reviews

TCS CodeVita 2014 Questions : Round2 (Set2)

No comments :

Question : Employee Hierarchy


Adam is working in a large hierarchical organization, where every employee, except the CEO, is either a supervisor or a sub-ordinate or both. Every employee will be identified by Employee ID. CEO of the company has 1 as his employee id. Every employee will get the salary (S) in accordance with their level and their performance. Given the data about the all the above mentioned details, your task is to find out the number of sub-ordinates with salary less than Adam.

Note: 

1. If an employee appears at two different levels, then consider the level which is near (best) to the CEO.
2. An employee is considered as sub-ordinate, if Adam is a direct or indirect supervisor to the said employee.

Input Format: 

Input consists of three parts, viz.
1. First Line contains, number of employees (N), number of supervisor-subordinate relationships (M) and Adam's employee id (A)
2. Next M lines follow, each line contains two employee Ids I, J which represents that I is a supervisor of J.
3. Salaries of N employees, delimited by space

Output Format: 

Print the total number of employees who are sub-ordinates to Adam and have salary less than Adam's.

Constraints:
1<=N<=50
1<=M<=1000
1<=I, J<=N
1<=S<=50000

Sample Input and Output


SNo.InputOutput
1
5 5 2
1 2
2 3
2 4
4 5
5 3
1500 2000 1500 2500 1800

2







K friends came to the city and they are in search of some nice flats to stay. At most they can spend T Rupees for the accommodation. Finally they came to know about Marika Apartments, where there exist N empty flats, and every flat owner is allowing at-most Pj persons to stay in a jth flat. So finally they have decided to stay in the multiple flats, at the same time they would like to stay in such flats in which every person from the K person group should able to reach the other K-1 friends who are actually staying either in the same flat or in the other flat.

Let Rj define the rent of the jth flat. One of the major problem in the apartment is only few flats are reachable from the other and one can take the advantage of one flat to reach the other in an indirect way. Now having all the above information your task is to help K friends to know how many options are available for them to stay.

Input Format: 

Input consists of four parts, viz.
First Line contains, number of friends (K), number of flats (N) and total paying capacity (T)
Next N lines contain N spaced integers, which represents the connectivity between the N flats. The connectivity between the flats are directional in nature and if Jth flat is reachable from Ith flat then it will be marked as 1
Next line contains N spaced integers Pj, each represents the maximum allowed persons in the jth flat.
Last line contains N spaced integers Rj, each represents the rent of the jth flat.

Output Format: 

Print the number of options i.e. number of different ways in which K friends can have their space and stay connected too.

Constraints:
1<=K<=100
1<=N<=500
1<=T<=10 ^ 6
1<=Rj<=5000
1<=Pj<=100

Sample Input and Output


SNo.InputOutput
1
5 4 10000
0 0 1 1
1 0 0 0
0 1 0 0
0 0 0 1
5 4 3 2
2000 1500 1500 2500

1
2
13 4 10000
0 0 1 1
1 0 0 0
0 1 0 0
0 0 0 1
5 4 3 2
2000 1500 1500 2500

0

A string is said to be palindrome, if it reads the same from both the ends. Given a string S, you are allowed to perform cyclic shifts. More formally, you can pick any one character from any end (head or tail) and you can append that character at the other end. For example, if the string is "abc", then if we do a shift using the character at head position then the string becomes "bca". Similarly, if we do the shift using the character at the tail then the input string becomes "cab". Your task is to find out the minimum number of shifts needed to make the given string, a palindrome. In case, we can't convert the string to palindrome then print -1.

Input Format: 

First line starts with T i.e. number of test cases, and then T lines will follow each containing a string "S".

Output Format:

Print the minimum number of cyclic shifts for each string if it can be made a palindrome, else -1.

Constraints:
1<=T<=100
1<=|S|<=300, S will contains only lower case alphabets ('a'-'z').

Sample Input and Output


SNo.InputOutput
1
4
abbb
aaabb
aabb
abc

-1
1
1
-1

Explanation: 

For Test Case 2 (aaabb): 
Shift the character at the tail to the head and the result will be "baaab", which is a palindrome. This is an operation which requires minimum number of shifts to make the given string a palindrome.

For Test Case 3 (aabb): 
One way to convert the given string to palindrome is, shift the character at the head to the tail, and the result will be "abba", which is a palindrome. Another way is to shift the character at the tail to the head, and the result will be "baab", which is also a palindrome. Both require only one shift.


Important Note: 

Please do not use package and namespace in your code. For object oriented languages your code should be written in one class.
Participants submitting solutions in C language should not use functions from / as these files do not exist in gcc

TCS CodeVita 2014 Questions : Round2 (Set1)

No comments :
Question : Valid Segments

Consider text comprised of sentences and sentences comprised of words. Words in a sentence will be space delimited. Text will comprise of two types of words, viz. alpha words and beta words. Alpha words are denoted in the input. All words in the text which are non-alpha words are beta words. Task is to find out the number of valid segment with number of beta words in the given range [lb, ub].

A segment is said to be valid if
- It contains all the K-strings
- It should start and end with any one of the K-strings

Input Format: 
First line contains the text. Next line contains K, lb, ub. Next K lines consist of alpha words in the text.

Note: 
1. String comparison should be case insensitive.
2. String comparison should be based only on words comprised of alphabets. Non-alphabet characters such as Full Stop ("."), Exclamation Marks ("!") etc. are called as Stop words. Stop words must be removed from sentences before comparison.
3. If more than one segment starts with the same index (i.e. position of the word in the text), then consider the shortest segment. In other words, segments should begin from unique indexes.

Output Format: 

Print the number of valid segments with number of beta words in the given range [lb, ub].

Constraints:
1<= total number of words in the text <= 30,000
1<= length of alpha and beta words <= 500
1<=K<=total number of alpha words
1<=lb<=ub<=total number of beta words

Sample Input and Output


SNo.InputOutput
1
The European market crashes on Mondays. Crashes in the European market are quite common.
2 3 4
European
Crashes

1

Explanation: 
Valid segments are:
European market crashes
crashes on Mondays. Crashes in the European
Crashes in the European

There is only one valid segment with number of beta words in the range [3, 4], which is segment 2.



A is the square matrix of size N. Every entry in the matrix will contain a lower case alphabet. Given Z strings, for each string your task is to find out the closest square-matrix starting from (1, 1). Closeness between the sub-matrix and the string is defined as, number of similar characters between the two. The input is guaranteed to have at least one character that is same in string Zi and matrix A, where Zi is the ith string. The same cell in the sub-matrix of A cannot be counted more than once to match with the character in the S.

Input Format: 
First line of input will consist of T Test cases. Each test case will consist of four parts, viz.
1. Size of the matrix (N)
2. The matrix itself (A = N * N) where elements are delimited by space.
3. Number of Strings (Z)
4. Z lines each comprising of string S

Output Format: 
For every string print the bottom right co-ordinates of the square-matrix closest from (1, 1).

Constraints:
1<=T<=5
1<=N<=500
'a'<=Aij<='z', where Aij is the entry of the matrix at ith row and jth column(1-index based). 
1<=Z<=25000
1<=|S|<=500

Sample Input and Output
SNo.InputOutput
1
1
4
a e r d
p l x l
l p x z
c q x o
3
apple
alex
aero

3 3
3 3
4 4

Explanation:
String S: "apple"
Sub matrix: (1, 1) to (3, 3)
a e r
p l x
p x
Sub matrix contains all characters of string S, hence the output




Given a list of unique employee ids and their age information, your task is to design a program to support the certain operations. Broadly speaking there are two operations, Insert and Query. You can assume that insert operations are unique on the employee_id column. Query operations are of 3 types. Both insert and query operations are described below.

1. A {employee_id} {age} 
    Operation will add the employee_id and age.
    Syntax: A {employee_id} {age}
    Returns: None

2. Q 1 {employee_id} 
    Query will search for the records whose employee id is {user_employee_id}.
    Syntax: Q 1 {employee_id}
    Returns: Boolean (True or False)

3. Q 2 {employee_id} 
    Query will search for the records whose employee id starts with {user_employee_id}.
    Syntax: Q 2 {employee_id}
    Returns: Total count of the records which matches the search criteria.

4. Q 3 {employee_id} {lb} {ub}
    Query will search for the records for which employee id starts with {user_employee_id} and age is in the range (lb, ub).
    Syntax: Q 3 {employee_id} {lb} {ub}
    Returns: Total count of the records which matches the search criteria.

Input Format: 

Every input line consists of either Add (A) or Query (Q) operation. -1 represents the end of input.

Output Format: 

Print the total number of resultant records in case of Query operation.

Constraints:
1 <= Total digits in the Employee ID <= 50
20 <= Age <= 100
10 <=lb<= 100, where lb is a multiple of 10.
lb <=ub<= 100, where ub is a multiple of 10.
Total number of add operations <= 40000
Total number of query operations <= 40000

Sample Input and Output

SNo.InputOutput
1
A 112345 20
A 112346 40
A 212347 40
A 212348 23
A 112449 30
Q 1 112345
Q 2 1123
Q 3 112 10 50
-1

True
2
3

NOTE: 
Minimum time required for evaluating this program is 24 seconds. Please be patient. Request you to wait up to a few minutes before resubmitting the same solution.

TCS Verbal Ability Test Sample Email : Set7

No comments :

TCS Verbal Ability Test Sample Email : Set6

No comments :

TCS Verbal Ability Test Sample Email : Set5

No comments :

TCS Verbal Ability Test Sample Email : Set4

No comments :

TCS Verbal Ability Test Sample Email : Set3

No comments :

TCS Verbal Ability Test Sample Email : Set2

No comments :

TCS Verbal Ability Test Sample Email : Set1

No comments :

How to get through campus placements

No comments :

You spent 2 excruciating years in a base camp called Kota or at a closed room studying dreadful ML Khanna’s maths or HC verma’s physics aiming to crack IIT-JEE and get into the best engineering college.


The dream fed away with you landing in a NIT, IIITS or so called other engineering colleges. The first & second years go in fun (bunking classes, hanging out with friends and doing all useless stuffs you know), the third year in dreams of a MNC and only worrying, watching seniors getting placed or getting rejected. Daydreaming about office and huge pay slips.

TCS Placement Pattern for 2015 Batch

No comments :

Well, placement season has started and the tech giant TCS is all set to recruit students from 2015 batch. TCS changes its recruitment process continuously. TCS changed its placement pattern for

How to answer HR interview questions

No comments :
Campus placement has become the largest parameter of judging a student in college.   If you get it you are successful and if not, you already know.





So you are in final year now

TCS CodeVita 2014 Questions : Round1 (Set2)

No comments :
Problem : Online Communities - Even Groups

In a social network, online communities refer to the group of people with an interest towards the same topic. People connect with each other in a social network. A connection between Person I and Person J is represented as C I J. When two persons belonging to different communities connect, the net effect is merger of both communities which I and J belonged to.

We are only interested in finding out the communities with the member count being an even number. Your task is to find out those communities.

Input Format:

Input will consist of three parts, viz.

1. The total number of people on the social network (N)
2.Queries 
  • C I J, connect I and J
  • Q 0 0, print the number of communities with even member-count
-1 will represent end of input.

Output Format:

For each query Q, output the number of communities with even member-count

Constraints:

1<=N<=10^6

1<=I, J<=N

Sample Input and Output

SNo.InputOutput
1
5
Q 0 0
C 1 2
Q 0 0
C 2 3
Q 0 0
C 4 5
Q 0 0
-1

0
1
0
1


Note:

Please do not use package and namespace in your code. For object oriented languages your code should be written in one class.
Note:

Participants submitting solutions in C language should not use functions from as these files do not exist in gcc




Problem : Matrix Rotations

You are given a square matrix of dimension N. Let this matrix be called A. Your task is to rotate A in clockwise direction byS degrees, where S is angle of rotation. On the matrix, there will be 3 types of operations viz. 
  1. Rotation
    Rotate the matrix A by angle S, presented as input in form of A S 
  2. Querying
    Query the element at row K and column L, presented as input in form of Q K L
  3. Updation
    Update the element at row X and column Y with value Z,  presented as input in form of U X Y Z
Print the output of individual operations as depicted in Output Specification


Input Format:

Input will consist of three parts, viz.
1. Size of the matrix (N)
2. The matrix itself (A = N * N)
3. Various operations on the matrix, one operation on each line. (Beginning either with A, Q or U)

-1 will represent end of input.
Note:
  • Angle of rotation will always be multiples of 90 degrees only.
  • All Update operations happen only on the initial matrix. After update all the previous rotations have to be applied on the updated matrix

Output Format:

For each Query operation print the element present at K-L location of the matrix in its current state.

Constraints:

1<=N<=1000
1<=Aij<=1000
0<=S<=160000
1<=K, L<=N
1<=Q<=100000


Sample Input and Output

SNo.InputOutput
1
2
1 2
3 4
A 90
Q 1 1
Q 1 2
A 90
Q 1 1
U 1 1 6
Q 2 2
-1

3
1
4
6


1 2
3 4

After 90 degree rotation, the matrix will become
3 1
4 2
Now the element at A11 is 3 and A12 is 1.

Again the angle of rotation is 90 degree, now after the rotation the matrix will become
4 3
2 1
Now the element at A11 is 4.

As the next operation is Update, update initial matrix i.e.
6 2
3 4

After updating, apply all the previous rotations (i.e. 180 = two 90 degree rotations).
The matrix will now become
4 3
2 6
Now A22 is 6.



Note:

Please do not use package and namespace in your code. For object oriented languages your code should be written in one class.
Note:

Participants submitting solutions in C language should not use functions from as these files do not exist in gcc


Problem : Compiler Design - Limit the Method Instructions

Raj is a newbie to the programming and while learning the programming language he came to know the following rules: 
-         Each program must start with '{' and end with '}'.
-         Each program must contain only one main function. Main function must start with '<' and end with '>'.
-         A program may or may not contain user defined function(s). There is no limitation on the number of user defined functions in the program. User defined function must start with '(' and end with ')'.
-         Loops are allowed only inside the functions (this function can be either main function or user defined function(s)). Every loop must start with '{' and end with '}'.
-         User defined function(s) are not allowed to be defined inside main function or other user defined function(s).
-         Nested loops are allowed.
-         Instructions can be anywhere inside the program.
-         Number of instructions inside any user defined function must not be more than 100.

If any of the above conditions is not satisfied, then the program will generate compilation errors. Today Raj has written a few programs, but he is not sure about the correctness of the programs. Your task is to help him to find out whether his program will compile without any errors or not.

Input Format:

First line starts with T, number of test cases. Each test case will contain a single line L, where L is a program written by Raj.

Output Format:

Print "No Compilation Errors" if there are no compilation errors, else print "Compilation Errors".

Constraints:

1<=T<=100

L is a text and can be composed of any of the characters {, }, (, ), <, >and P, where P will represents the instruction.

L, comprised of characters mentioned above should be single spaced delimited.
Number of characters in the text, |L| < = 10000

Sample Input and Output


SNo.InputOutput
1
3
{ < > ( P ) }
{ < { } > ( { } ) )
{ ( { } ) }

No Compilation Errors
Compilation Errors
Compilation Errors


Note:

Please do not use package and namespace in your code. For object oriented languages your code should be written in one class.
Note:

Participants submitting solutions in C language should not use functions from as these files do not exist in gcc