Take FREE!! Online AMCAT Mock Test to Crack Wipro NLTH, Capgemini, etc.
Get Off-Campus Placement Jobs Info !!!
Practice Given Here Wipro NLTH Practice Q&A

391 / 404

A Derangement is a permutation of n elements, such that no element appears in its original position. For example, a derangement of {0, 1, 2, 3} is {2, 3, 1, 0}.

Given a number n, find the total number of Derangements of a set of n elements.

Input : 1st Input: n = 2

For two elements say {0, 1}, there is only one
possible derangement {1, 0}

2nd Input: n = 3

For three elements say {0, 1, 2}, there are two
possible derangements {2, 0, 1} and {1, 2, 0}

Output :

|  Basics | | | |  Experience, Fresher

392 / 404

Every character in the input string is followed by its frequency.
Write a function to decrypt the string and find the nth character of the decrypted string. If no character exists at that positionthen then return "-1".
For eg:- If the input string is "a2b3" the decrypted string is "aabbb".
Note: The frequency of encrypted string cannot be greater than a single digit i.e.<10.

Explanation:

The decrypted string is "abccc", hence the 5th character in the decrypted string is "c".

Input : Input Specification:
Input1: A string.
Input2:5

Output :

|  Basics | | | |  Experience, Fresher

393 / 404

Given a number of objects N(non-repetitive object) Find the number of arrangements in which no objects occur at original positions.

Input : Input1: N, the number of Objects.
Input1: 3

Output :

|  Basics | | | |  Experience, Fresher

394 / 404

Consider the following series: 1,1,2,3,4,9,8,27,16,81,32,243,64,729,128,2187…

This series is a mixture of 2 series - all the odd terms in this series form a geometric series and all the even terms form yet another geometric series. Write a program to find the Nth term in the 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 value of n th term,no other character / string or message should be written to STDOUT. For example , if N=16, the 16th term in the series is 2187, so only value 2187 should be printed to STDOUT.

You can assume that N will not exceed 30.

Input : if N=16

Output :

|  Basics | | | |  Experience, Fresher

395 / 404

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 | | | |  Experience, Fresher

396 / 404

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 | | | |  Experience, Fresher

397 / 404

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 | | | |  Experience, Fresher

398 / 404

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 | | | |  Experience, Fresher

Tags:Wipro NLTH

399 / 404

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 | | | |  Experience, Fresher

Tags:Wipro NLTH

400 / 404

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 | | | |  Experience, Fresher

Tags:Wipro NLTH

+ Contribute Programming Qs.

Baig
1