TCS NQT Array and String Practice Questions
1. Find the Second Largest Number
A company stores the sales records of its employees in an array. Your task is to identify the
employee with the second-highest sales figure.
Input:
5
10 20 30 40 50
Output:
40
2. Move All Zeros to End
A data processing system stores valid entries as non-zero values and invalid entries as zeros.
Rearrange the array such that all invalid entries appear at the end while maintaining the order of
valid entries.
Input:
6
102045
Output:
124500
3. Reverse a String
A company encrypts its employee IDs by reversing them. Given a string, write a program to
generate its encrypted form.
Input:
TCSNQT
Output:
TQNSCT
4. Check Palindrome
A security system accepts only special access codes that remain the same when read from left to
right and right to left.
Input:
MADAM
Output:
Palindrome
5. Find Missing Number
A warehouse stores product IDs numbered from 1 to N. Due to a system error, one product ID is
missing from the database.
Input:
5
1245
Output:
3
6. Character Frequency
A text analyzer needs to determine how many times a specific character appears in a given string.
Input:
TCSNQT
T
Output:
2
7. Remove Duplicates from Array
An online registration portal accidentally stores duplicate registration numbers. Remove duplicate
entries and display unique registration numbers.
Input:
7
1232415
Output:
12345
8. Check Anagram
Two words are considered equivalent if they contain the same characters with the same frequency.
Input:
listen
silent
Output:
Anagram
9. Rotate Array by K Positions
A circular conveyor belt contains N items. After every cycle, the belt rotates K positions to the right.
Input:
5
12345
2
Output:
45123
10. Longest Word in a Sentence
A text editor wants to highlight the longest word in a sentence for readability analysis.
Input:
TCS coding practice is important
Output:
important
11. Maximum Subarray Sum
A stock analyst records daily profit and loss values. Find the maximum profit that can be obtained
from a continuous sequence of days.
Input:
8
-2 -3 4 -1 -2 1 5 -3
Output:
7
12. First Non-Repeating Character
A communication system receives a message stream. Find the first character that appears only
once.
Input:
swiss
Output:
w
13. Largest and Smallest Element
An examination system stores marks of students. Find the highest and lowest marks obtained.
Input:
5
45 90 67 23 88
Output:
Largest = 90
Smallest = 23
14. Count Vowels and Consonants
A language analyzer needs to count vowels and consonants present in a word.
Input:
education
Output:
Vowels = 5
Consonants = 4
15. Longest Substring Without Repeating Characters
A network monitoring system records a stream of unique packet IDs. Find the length of the longest
sequence without repetition.
Input:
abcabcbb
Output:
3