TATA Consultancy Services Interview Questions
- 0of 0 votes
Answersin linux threads are called light weight processes. Whether process or thread, they are implemented by task_struct data structure. 1>So, in that sense how kernel distinguishes between thread and process.
- mohapatrasandeep60 March 25, 2016 in India
2> when context switching happens, how threads get less overhead in context switching. because prior to this thread, another thread from another process may be running. So kernel should load all resources even if resources are shared between threads of a processes| Report Duplicate | Flag | PURGE
TATA Consultancy Services - 0of 0 votes
Answercan you call exit(0) inside a signal handler in Linux. Will there be a crash
- mohapatrasandeep60 March 21, 2016 in India| Report Duplicate | Flag | PURGE
TATA Consultancy Services - 0of 0 votes
Answersint pfd[2];
- mohapatrasandeep60 March 21, 2016 in India
if (pipe(pfd) == -1) /* Create the pipe */
errExit("pipe");
what happens if we write or read to both pfd[0] and pfd[1] simultaneously
how to handle such condition| Report Duplicate | Flag | PURGE
TATA Consultancy Services - 0of 0 votes
Answerswhat happens if time of pthread_cond_timedwait expires?
- mohapatrasandeep60 March 21, 2016 in India| Report Duplicate | Flag | PURGE
TATA Consultancy Services - 0of 0 votes
Answerswe create a pipe
- mohapatrasandeep60 March 21, 2016 in United States
int pfd[2];
if (pipe(pfd) == -1) /* Create the pipe */
errExit("pipe");
what will happen if we write to or read from both pfd[0], pfd[1] simultaneously
how to handle such a situation| Report Duplicate | Flag | PURGE
TATA Consultancy Services Tech Lead - 0of 0 votes
Answers-2
- mohapatrasandeep60 March 21, 2016 in United States
down vote
favorite
In TCP sockets, there is a connection between Ip1,port1 to IP2,port2; how is this connection maintained , how it is different from UDP socket| Report Duplicate | Flag | PURGE
TATA Consultancy Services Tech Lead - 0of 0 votes
Answersis there anything wrong in the code
- mohapatrasandeep60 March 18, 2016 in India
class B
{
~B(){}
public:
void Destroy()
{
delete this;
}
};
int main() {
B* b = new B();
b->Destroy();
return 0;
}
why you cant create object of class b on stack| Report Duplicate | Flag | PURGE
TATA Consultancy Services - 0of 0 votes
AnswersJack love playing games, Gluttonous snake( an old game in Nokia era) is one of his favorite. However, after playing gluttonous snake so many times, he finally got bored with the game, so he changed the rules:
- mirrorme March 12, 2016 in United States
Rule 1: Write a code to find the Max sum path in a grid (2-D array), with dimension with n rows and m column (1<=n,m<=500)
Rule 2: In the 2D Array, each cell (elements) contains a value v in the array is from (-1<=v<=99999)
Rule 3. You can start from any position of the leftest column (border) of the array to the rightest(border) column of the array to calculate the Max Sum path.
Rule 4. You can move up, right, down, and CAN'T move left, and can visit each element only one time.
Rule 5.If the element is -1, it means the path is blocked, and you can't go through the path (calculate it in the sum), you have to choose other path to calculate the sum.
For example, if a 4*4 array grid
{{-1,3,2,1}
{2,-1,2,4}
{2,2,-1,3}
{4,2,1,2}};
The max sum path is : (from grid[4][0])
4-->up-->2-->left-->2-->down-->2-->left-->
1-->left-->2-->up-->3-->up-->4-->up-->1
and the sum is 4+2+2+2+1+2+3+4+1 =21
Thank you
Here is my code, I am new in Java and there is still lots of improvements
import java.util.*;
public class MainClass {
public static void main(String[] args) {
@SuppressWarnings("resource")
Scanner rowDimension = new Scanner(System.in);
System.out.print("Enter the number of rows: ");
int firstInput = rowDimension.nextInt();
@SuppressWarnings("resource")
Scanner columnDimension = new Scanner(System.in);
System.out.print("Enter the number of columns: ");
int secondInput = columnDimension.nextInt();
//Input two number to generate 2D Array
Integer [][] array = new Integer[firstInput][secondInput];
//The purpose of the array is check the wall (cell value = -1)
boolean [][] visited = new boolean[firstInput][secondInput];
//Use Math.random() to generate the cell of the array
int[][] randomTable = new int[firstInput][secondInput];
for (int row = 0; row < firstInput; row++) {
for (int column = 0; column < secondInput; column++) {
// multiply by 1000000 to get a number between 0 and 99999
randomTable[row][column] = (int)(Math.random() * 1000000 -1);
System.out.print(randomTable[row][column] + " ");
}
System.out.println();
}
//Start form the left-down location of grid
int i = firstInput-1, j = 0;
visited[i][j] = true;
double sum = array[i][j];
while(true)
{
int max = -1;
int maxi = 0, maxj = 0;
//Case1 : choose path: UP
if(i-1 >= 0 && i-1<= firstInput-1 && j>=0 && j<= secondInput-1 && array[i-1][j] != null && array[i-1][j]>max && !visited[i-1][j])
{
max = array[i-1][j];
maxi = i-1;
maxj = j;
}
//Case2 : choose path: Down
if(i+1 >= 0 && i+1<= firstInput-1 && j>=0 && j<= secondInput-1 &&array[i+1][j] != null && array[i+1][j]>max && !visited[i+1][j])
{
max = array[i+1][j];
maxi = i+1;
maxj = j;
}
//Case3 : choose path: Right
if(i >= 0 && i<= firstInput-1 && j+1>=0 && j+1<= secondInput-1 && array[i][j+1] != null && array[i][j+1]>max && !visited[i][j+1])
{
max = array[i][j+1];
maxi = i;
maxj = j+1;
}
i = maxi;
j = maxj;
visited[i][j] = true;
sum += max;
//To the destination : Right-Up location of the grid
if(i == 0 && j == secondInput-1)
break;
}
System.out.println(sum);
}
}| Report Duplicate | Flag | PURGE
TATA Consultancy Services Software Developer Java - 0of 0 votes
AnswersWrite a program to balance the binary search tree ?
- mithleshtechno February 21, 2016 in United States
with explanation and preferred
C language..| Report Duplicate | Flag | PURGE
TATA Consultancy Services Software Developer - 0of 0 votes
AnswerA pole of infinite length is planted vertically on the ground. A stone is placed at a distance of 'd1' meters from the pole towards the right. A bird is sitting on the ground exactly in the middle of the pole and stone. The bird flies away towards the right in such a manner that its distance from the pole and the distance between the bird and the stone at any point of time is always equal. Calculate the distance between the bird and it's starting point after n seconds if the bird is covering 'd2'metres horizontally every second.
- miracles.asa August 08, 2015 in India
Input Format:
First line contains the distance between pole and stone, denoted by d1
Second line contains the flying velocity of bird per second, denoted by d2 meters/ sec
Third line contains time since the bird started flying, denoted n
Output Format:
Print the distance between the bird's position after n seconds and its initial position in meters
OR
Print "Invalid Input" if any constraints are violated
Constraints:
d1 >0
d2 > 0
n > 0
Calculation and printing of output should be upto 11 precision| Report Duplicate | Flag | PURGE
TATA Consultancy Services Software Engineer test - 0of 0 votes
Answersadvantages and disadvantages of Circular queue according to its implementation in array and linkedlist ??
- rahulkumar5july May 26, 2015 in India| Report Duplicate | Flag | PURGE
TATA Consultancy Services SDE1 Data Structures - 0of 0 votes
AnswersWhat is composite key? How it differs from candidate key?
- kaustubh deshmukh June 19, 2014 in India| Report Duplicate | Flag | PURGE
TATA Consultancy Services Dev Lead Dev Lead SQL - 2of 4 votes
AnswersA teacher wanted 100 gems distributed in 7 purses such that number of gems in 7 purses should always sum up to 100. But his condition was that he can demand any number of gems between 1 to 100 and Shiva must be able to satisfy his demand without needing to open any purse. Also once Shiva packs the purses, he will not get another chance to rearrange the number of Gems in those 7 purses. So consider that these purses are sealed the moment Shiva puts appropriate number of Gems in it.
- chouhan.mayank August 14, 2013 in India
Out of affection, the teacher decided to step up the difficulty level so that Shiva can survive the turbulent world outside the Gurukul. The Guru added one more condition that out of 7 purses Guru will always fill one purse with any number of gems. Thus Shiva need to distribute remaining Gems in rest of the 6 purses.
As a new techie your task is to write a computer program to help Shiva in fulfilling his Guru's demand.| Report Duplicate | Flag | PURGE
TATA Consultancy Services Software Engineer / Developer Algorithm - 0of 0 votes
AnswersYou have a cake and you have a knife,you have to cut(straight) cake into 8 parts by using knife 3 times,
- muhammad.husnain.ashraf February 05, 2013 in pakistan
for example cutting cake horizontally and vertically from middle you had make cake in 4 parts by using 2 times knife| Report Duplicate | Flag | PURGE
Techlogix TATA Consultancy Services Software Engineer / Developer Consultant Brain Teasers - 0of 0 votes
AnswersWhat is the fastest way print output to STDOUT in Java?
- Karthik Sharma November 18, 2011 in India| Report Duplicate | Flag | PURGE
TATA Consultancy Services Software Engineer / Developer Java - 0of 0 votes
Answershow to detect/remove duplicate entries frm a database(for eg students). thr is no primary key
- anushree99 September 24, 2011 in -| Report Duplicate | Flag | PURGE
TATA Consultancy Services