Take FREE!! Online Mettl Mock Test to Crack TechM and Other Companies Written Exams.
Get Off-Campus Placement Jobs Info !!!
TCS NQT Technical and Managerial Round Interview Questions

# Programming Questions in JAVA Asked at Experienced

211 / 226

Consider the below series : 0,0,2,1,4,2,6,3,8,4,10,5,12,6,14,7,16,8
This series is a mixture of 2 series all the odd terms in this series form even numbers in ascending order and every even terms is derived from the previous term using the formula (x/2)

Write a program to find the nth term in this series.

The value n in a positive integer that should be read from STDIN the nth term that is calculated by the program should be written to STDOUT. Other than the value of the nth term no other characters /strings or message should be written to STDOUT.

For example if n=10,the 10 th term in the series is to be derived from the 9th term in the series. The 9th term is 8 so the 10th term is (8/2)=4. Only the value 4 should be printed to STDOUT.

You can assume that the n will not exceed 20,000.

Input : NA

Output : NA

|  Basics | | To Reading List | |  Experience, Fresher

212 / 226

Write an efficient program to find the sum of contiguous sub-array within a one-dimensional array of numbers which has the largest sum.

Input : {-2, -3, 3, -1, -2, 1, 5, -3}

Output :

|  Basics | | To Reading List | |  Experience, Fresher

213 / 226

Given an expression string exp. Examine whether the pairs and the orders of “{“,”}”,”(“,”)”,”[“,”]” are correct in exp.
For example, the program should print 'balanced' for exp = “[()]{}{[()()]()}” and 'not balanced' for exp = “[(])”

Input : The first line of input contains an integer T denoting the number of test cases. Each test case consists of a string of expression, in a separate line.

Output :

|  Basics | | To Reading List | |  Experience, Fresher

214 / 226

Write a program to find transpose of a square matrix mat[][] of size N*N. Transpose of a matrix is obtained by changing rows to columns and columns to rows.

Input : The first line of input contains an integer T, denoting the number of testcases. Then T test cases follow. Each test case contains an integer N, denoting the size of the square matrix. Then in the next line are N*N space separated values of the matrix.

Output :

|  Basics | | To Reading List | |  Experience, Fresher

Tags:Wipro NLTH

215 / 226

Given an array arr[] of N integers. Do the following operation n-1 times. For every Kth operation:

Right rotate the array clockwise by 1.
Delete the (n-k+1)th last element.

Now, find the element which is left at last.

Input : The first line of input contains an integer T denoting the number of test cases. Then T test cases follows. Each test case contains two lines. The first line of each test case contains an integer N. Then in the next line are N space separated values of the array arr[].

2
4
1 2 3 4
6
1 2 3 4 5 6

Output :

|  Basics | | To Reading List | |  Experience, Fresher

Tags:Wipro NLTH

216 / 226

Given an array of N positive integers, find GCD of all the array elements.

Input : Input: N = 3, arr[] = {2, 4, 6}

Explanation: GCD of 2,4,6 is 2.

Output :

|  Basics | | To Reading List | |  Experience, Fresher

Tags:Wipro NLTH

217 / 226

Given an unsorted array arr[] of positive integers. Find the number of triangles that can be formed with three different array elements as lengths of three sides of triangles.

Note:
A triangle is possible
with all the elements 5, 3 and 4.

Input : 3
3 5 4

Output :

|  Basics | | To Reading List | |  Experience, Fresher

Tags:Wipro NLTH

218 / 226

Given an array Arr of N positive integers and another number X. Determine whether or not there exist two elements in Arr whose sum is exactly X.

Explanation: Arr + Arr = 6 + 10 = 16

Input : N = 6, X = 16
Arr[] = {1, 4, 45, 6, 10, 8}

Output :

|  Basics | | To Reading List | |  Experience, Fresher

219 / 226

Given an integer N, count the numbers having an odd number of factors from 1 to N (inclusive).

Input : N = 5

Output :

|  Basics | | To Reading List | |  Experience, Fresher

Tags:Wipro NLTH

220 / 226

Given a String of length S, reverse the whole string without reversing the individual words in it. Words are separated by dots.

The first line contains T denoting the number of testcases. T testcases follow. Each case contains a string S containing characters.

Input : i.like.this.program.very.much

Output :

|  Basics | | To Reading List | |  Experience, Fresher

Tags:Wipro NLTH

+ Contribute Programming Qs.

#### Top Kudos Contributor  Vaishnav
1  Baig
1