TCS Interview Preparation (NQT)

55+ coding, DSA, aptitude, and HR questions with complete solutions for freshers.

QuestionAnswerCategory
Q1. Reverse a string.Use slicing or iterative reversal.
def reverse_string(s):
    return s[::-1]
Coding
Q2. Check leap year.Divisible by 400 OR (divisible by 4 AND not by 100).
def is_leap_year(year):
    return (year % 400 == 0) or (year % 4 == 0 and year % 100 != 0)
Coding
Q3. Convert vowels to uppercase.Iterate string, replace vowels with uppercase.
def convert_vowels(s):
    return ''.join([c.upper() if c in 'aeiou' else c for c in s])
Coding
Q4. Check if palindrome.Compare string with reverse. Ignore spaces/case.
def is_palindrome(s):
    s = s.replace(' ', '').lower()
    return s == s[::-1]
Coding
Q5. Find hypotenuse of triangle.Use Pythagorean theorem: c = sqrt(a² + b²).
import math
def hypotenuse(a, b):
    return math.sqrt(a**2 + b**2)
Coding
Q6. Check Armstrong number.Sum of digits raised to power of number of digits = number.
def is_armstrong(n):
    digits = [int(d) for d in str(n)]
    return sum(d**len(digits) for d in digits) == n
Coding
Q7. Two Sum problem.Use hashmap to store complements. O(n) time.
def two_sum(nums, target):
    seen = {}
    for num in nums:
        if target - num in seen:
            return [seen[target - num], nums.index(num)]
        seen[num] = nums.index(num)
    return []
Coding
Q8. Merge two sorted arrays.Two pointer technique. O(n+m) time.
def merge(arr1, arr2):
    result = []
    i = j = 0
    while i < len(arr1) and j < len(arr2):
        if arr1[i] <= arr2[j]:
            result.append(arr1[i])
            i += 1
        else:
            result.append(arr2[j])
            j += 1
    return result + arr1[i:] + arr2[j:]
Coding
Q9. Maximum element in array.Iterate and track maximum value.
def find_max(arr):
    return max(arr) if arr else None
Coding
Q10. Binary search.Divide search space in half. O(log n) on sorted array.
def binary_search(arr, target):
    left, right = 0, len(arr) - 1
    while left <= right:
        mid = (left + right) // 2
        if arr[mid] == target:
            return mid
        elif arr[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1
Coding
Q11. Fibonacci series.Each = sum of previous two. Start: 0, 1.
def fibonacci(n):
    a, b = 0, 1
    fib = []
    for _ in range(n):
        fib.append(a)
        a, b = b, a + b
    return fib
Coding
Q12. Factorial calculation.Product of all positive integers ≤ n.
def factorial(n):
    if n < 2:
        return 1
    return n * factorial(n - 1)
Coding
Q13. Prime number check.Check divisibility up to sqrt(n).
def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True
Coding
Q14. GCD of two numbers.Euclidean algorithm: gcd(a,b) = gcd(b, a%b).
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
Coding
Q15. Anagram check.Sort both strings and compare.
def are_anagrams(s1, s2):
    return sorted(s1) == sorted(s2)
Coding
Q16. Remove duplicates from sorted array.Two pointers. Count unique elements.Coding
Q17. Count character frequency.Hashmap approach. O(n) time.
def count_freq(s):
    freq = {}
    for c in s:
        freq[c] = freq.get(c, 0) + 1
    return freq
Coding
Q18. Rotate array by k.Slicing or reverse technique. O(n) time.
def rotate(arr, k):
    k = k % len(arr)
    return arr[-k:] + arr[:-k]
Coding
Q19. Valid parentheses.Stack: push open, pop close. Empty stack = valid.
def is_valid(s):
    stack = []
    mapping = {')': '(', '}': '{', ']': '['}
    for char in s:
        if char in mapping:
            if not stack or stack[-1] != mapping[char]:
                return False
            stack.pop()
        else:
            stack.append(char)
    return len(stack) == 0
Coding
Q20. Longest substring without repeating.Sliding window with hashmap. O(n) time.Coding
Q21. Average speed calculation.Speed = Total Distance / Total Time.Aptitude
Q22. Simple interest.SI = (P × R × T) / 100. Where P=principal, R=rate, T=time.Aptitude
Q23. Percentage calculation.Percentage = (Value / Total) × 100.Aptitude
Q24. Compound interest.A = P(1 + R/100)^T. Interest = A - P.Aptitude
Q25. Discount calculation.Discount = Original Price × (Discount % / 100).Aptitude
Q26. Work rate problem.Combined rate = 1/A + 1/B. Time = 1 / Combined rate.Aptitude
Q27. Ratio proportion.If a:b = c:d then a/b = c/d.Aptitude
Q28. Area of rectangle.Area = Length × Width.Aptitude
Q29. Area of circle.Area = π × r².Aptitude
Q30. Perimeter of rectangle.Perimeter = 2 × (Length + Width).Aptitude
Q31. Tell me about yourself.Education, projects, internships, skills, why TCS.HR
Q32. Why TCS?IT leader, global presence, innovation, career growth, training.HR
Q33. Your strengths.Problem-solving, teamwork, communication, adaptability, learning.HR
Q34. Reverse linked list.Three pointers: prev, curr, next. Reverse iteratively.Coding
Q35. Second largest element.Track first and second. O(n) time, O(1) space.Coding
Q36. Missing number in array.Expected sum minus actual sum.Coding
Q37. Array intersection.Use hashset. O(n+m) time.Coding
Q38. Duplicate in array.Floyd cycle detection or hashmap approach.Coding
Q39. Maximum subarray sum (Kadane).Track current and max sum. Reset if negative.
def max_subarray(arr):
    max_sum = curr_sum = arr[0]
    for num in arr[1:]:
        curr_sum = max(num, curr_sum + num)
        max_sum = max(max_sum, curr_sum)
    return max_sum
Coding
Q40. Merge sort.Divide, sort, merge. O(n log n) always.Coding
Q41. Pressure handling.Prioritize, break problems, communicate, stay focused.HR
Q42. Salary expectations.Research IT sector. Give realistic range.HR
Q43. Bubble sort.Compare adjacent, swap. O(n²) worst case.Coding
Q44. Selection sort.Find minimum, swap. O(n²) always.Coding
Q45. Insertion sort.Build sorted array incrementally. O(n²) worst, O(n) best.Coding
Q46. Team collaboration.STAR method: situation, task, action, result.HR
Q47. LCM calculation.lcm(a,b) = (a*b) / gcd(a,b).Coding
Q48. Transpose matrix.Swap rows and columns.Coding
Q49. Matrix addition.Add corresponding elements. O(n²).Coding
Q50. Career goals in 5 years.Senior developer, team lead, or specialist role.HR
Q51. String reversal without built-in.Use loop to build reversed string.Coding
Q52. First non-repeating character.Hashmap: return first with count = 1.Coding
Q53. Common elements in arrays.Use set intersection or two pointers.Coding
Q54. Sum of digits.Iterate digits, add them up.
def sum_of_digits(n):
    return sum(int(d) for d in str(n))
Coding
Q55. How do you learn new tech?Courses, projects, documentation, hands-on practice.HR