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

# Coding Questions Asked in HackerRank

21 / 29

Deleting Sub-strings

There are two strings, s, and t.

Perform two operationss with the string s:
1. Working from left-to-right delete each occurrence of t in s until there are no more occurrences of t. Count each deletion.
2. working from right-to-left delete each occurrence of t in s until there are no more occurrences of t. Count each deletion.

When that is done, return the greater of the two counts; deletion left-to-right or deletions right-to-left.

Example
s = 'bcbbc'
t = 'b'

From left to right:
Remove th first occurrence t = 'b' from"

Input : NA

Output : NA

|  Strings | | | |  Fresher

Tags:SAP Labs

22 / 29

Given a list of distinct unsorted integers, find the pair of elements that have the smallest absolute difference between them? If there are multiple pairs, find them all.
Input : arr[] = {10, 50, 12, 100}
Output : (10, 12)
The closest elements are 10 and 12

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

Output :

|  Strings | | | |  Fresher

Tags:SAP Labs

23 / 29

Car parking problem. An array given represents the actual order of cars need to be parked. Like for example order is 4,6,5,1,7,3,2,empty. If cars are parked in some order like empty,1,2,3,7,6,4,2. Some person needs to get them into the correct order, list out all instructions to the person to get in the correct order with least number of swaps.

Input : NA

Output : NA

|  Sorting | | | |  Experience, Fresher

Tags:Amazon

24 / 29

There are many cars parked in the parking lot. The parking is a straight very long line and a parking slot for every single meter. There are cars parked currently and you want to cover them from the rain by building a roof. The requirement is that at least k cars are covered by the roof. What's the minimum length of the roof that would cover k cars?

The function has the following parameters:
cars: integer array of length denoting the parking slots where cars are parked
k: integer denoting the number of cars that have to be covered by the roof

Example:
Input:
cars: [2, 10, 8, 17]
k: 3
output: 9
Explanation: you can build a roof of length 9 covering all parking slots from the 2nd one to the 10th one, so covering 3 cars at slots 2, 10, 8, there are no shorter roof that can cover 3 cars, so the answer is 9

Note:
1 <= n <= 10^5
1 <= k <= n
1 <= cars[i] <= 10^14
All slots token by cars are unique

Input : cars: [2, 10, 8, 17]
k: 3

Output :

|  Sorting | | | |  Experience, Fresher

Tags:Amazon

25 / 29

Return the character which occurs for the maximum numbers of times in the Input String.
If multiple characters occur with the same highest frequency then return "0".

Input : Input1: abcdd

Output :

|  Strings | | | |  Experience, Fresher

26 / 29

A prime number is a whole number greater than 1 that is divisible only by itself and the number 1.

Given 'n' (1 <= n <= 100000), find the nth prime number.

Input : An integer n

Output :

|  Basics | | | |  Experience, Fresher

27 / 29

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

28 / 29

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

29 / 29

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

+ Contribute Programming Qs.

Baig
1