Master One Language
- Choose C, C++, Java, or Python
- Master syntax, data structures, and basic algorithms
- Practice daily coding problems
Practice TCS placement paper coding questions with detailed solutions. Access TCS NQT programming logic questions and hands-on coding problems in C, C++, Java, Python.
This page contains TCS coding questions from TCS NQT placement papers with detailed solutions. Practice TCS programming logic questions and TCS hands-on coding problems to prepare for TCS NQT coding section.
TCS NQT Coding Section Breakdown:
Total Coding Questions: 11-17 questions
#include <stdio.h>int main() { int x = 5; printf("%d", x++ + ++x); return 0;}Solution:
x++ is post-increment: uses value 5, then increments to 6 ++x is pre-increment: increments 6 to 7, then uses value 7
Result: 5 + 7 = 12
Answer: 12
int i = 0;while (i < 5) { printf("%d ", i); i++;}Solution:
Loop executes for i = 0, 1, 2, 3, 4 (5 times)
Answer: 5 times
Problem Statement: Given an array of integers, find the second largest element.
Example:
Input: [12, 35, 1, 10, 34, 1]Output: 34Solution (Java):
public int findSecondLargest(int[] arr) { if (arr.length < 2) return -1;
int largest = Integer.MIN_VALUE; int secondLargest = Integer.MIN_VALUE;
for (int num : arr) { if (num > largest) { secondLargest = largest; largest = num; } else if (num > secondLargest && num != largest) { secondLargest = num; } }
return secondLargest == Integer.MIN_VALUE ? -1 : secondLargest;}Time Complexity: O(n)
Space Complexity: O(1)
Problem Statement: Given a string, reverse the order of words.
Example:
Input: "the sky is blue"Output: "blue is sky the"Solution (Java):
public String reverseWords(String s) { String[] words = s.trim().split("\\s+"); StringBuilder result = new StringBuilder();
for (int i = words.length - 1; i >= 0; i--) { result.append(words[i]); if (i > 0) result.append(" "); }
return result.toString();}Time Complexity: O(n)
Space Complexity: O(n)
Problem Statement: Given an array, rotate it to the right by k steps.
Example:
Input: nums = [1,2,3,4,5,6,7], k = 3Output: [5,6,7,1,2,3,4]Solution (Java):
public void rotate(int[] nums, int k) { int n = nums.length; k = k % n;
reverse(nums, 0, n - 1); reverse(nums, 0, k - 1); reverse(nums, k, n - 1);}
private void reverse(int[] nums, int start, int end) { while (start < end) { int temp = nums[start]; nums[start] = nums[end]; nums[end] = temp; start++; end--; }}Time Complexity: O(n)
Space Complexity: O(1)
Problem Statement: Given a number, determine if it is a palindrome.
Example:
Input: 121Output: trueSolution (Java):
public boolean isPalindrome(int x) { if (x < 0) return false;
int original = x; int reversed = 0;
while (x > 0) { reversed = reversed * 10 + x % 10; x /= 10; }
return original == reversed;}Time Complexity: O(log n)
Space Complexity: O(1)
Problem Statement: Given a number n, calculate n! (factorial).
Example:
Input: 5Output: 120Solution (Java):
public long factorial(int n) { if (n <= 1) return 1;
long result = 1; for (int i = 2; i <= n; i++) { result *= i; }
return result;}Time Complexity: O(n)
Space Complexity: O(1)
Master One Language
Focus on Fundamentals
Time Management
TCS 2024 Papers
Previous year papers with coding questions and solutions
TCS 2025 Papers
Latest papers with current year coding questions
TCS Aptitude Questions
TCS aptitude questions with solutions
TCS Preparation Guide
Comprehensive preparation strategy for TCS NQT
TCS Main Page
Complete TCS placement guide
Practice TCS coding questions regularly to master programming fundamentals!