{"id":111354,"date":"2025-08-28T14:19:44","date_gmt":"2025-08-28T08:49:44","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/"},"modified":"2025-08-28T13:18:04","modified_gmt":"2025-08-28T07:48:04","slug":"tcs-nqt-coding-questions-answers","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/","title":{"rendered":"TCS NQT Coding Questions and Answers (with code)"},"content":{"rendered":"\n<p>Want to crack the TCS NQT coding section? It's a guide to help you. We'll cover the patterns, the types of questions they throw at you, and how to solve them without unnecessary complexity.<\/p>\n\n\n\n<p>The coding section is where they separate the people who can talk about code from the people who can write it. Your goal is to pass the test cases. Let's get straight to it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"understanding-the-nqt-coding-section\">Understanding the NQT Coding Section<\/h2>\n\n\n\n<p>Before diving into problems, understand the structure and common challenges of the NQT coding section.<\/p>\n\n\n\n<p><strong>Structure (The Integrated Test Pattern):<\/strong> TCS now uses a single 190-minute exam to decide all three job profiles. The test is strictly divided into: <\/p>\n\n\n\n<p><strong>Part A:<\/strong> Foundation (75 mins for basic aptitude\/verbal) <br><strong>Part B: <\/strong>Advanced (115 mins for advanced math, reasoning, and coding). <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>The Coding Section:<\/strong> You will specifically face <strong>2 coding questions<\/strong> in the Advanced section, with a shared time limit of 90 minutes.<\/li>\n\n\n\n<li><strong>Roles &amp; Difficulty:<\/strong> > * <strong>Ninja (~3.36 LPA):<\/strong> Heavily dependent on acing the Part A Foundation section and clearing basic cutoffs.<\/li>\n\n\n\n<li><strong>Digital (~7.0 LPA) &amp; Prime (~9.0 - 12.0 LPA):<\/strong> You must conquer Part B. The two coding questions generally range from Moderate to Hard. Solving one fully and passing edge cases on the second secures a Digital interview. Solving both perfectly puts you in the Prime category. <\/li>\n\n\n\n<li><strong>Languages Allowed:<\/strong> You can use C, C++, <a href=\"https:\/\/www.mygreatlearning.com\/blog\/java-tutorial-for-beginners\/\">Java<\/a>, <a href=\"https:\/\/www.mygreatlearning.com\/blog\/python-tutorial-for-beginners-a-complete-guide\/\">Python<\/a>, or Perl. Pick the language you are most comfortable debugging under pressure. <\/li>\n\n\n\n<li><strong>The Strict Test Environment:<\/strong> The TCS iON compiler is notorious for being picky about input\/output formats and whitespace. More importantly for 2026, physical rough paper is completely banned. You must use the on-screen rough pad and calculator. AI proctoring is incredibly strict, looking down at your desk will trigger warnings and potential disqualification.<\/li>\n<\/ul>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/applied-data-structures-algorithms-in-java\" class=\"courses-cta-title-link\">Java DSA Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Learn Data Structures &amp; Algorithms (DSA) in Java to excel in coding interviews and software development. Master linked lists, trees, graphs, heaps, hashing, sorting, and more while building efficient, optimized solutions.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>2 projects<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>14 hrs<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/applied-data-structures-algorithms-in-java\" class=\"courses-cta-button\">\n                Data Structures Java Course\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"the-most-important-skill-handling-input\">The Most Important Skill: Handling Input<\/h2>\n\n\n\n<p>This is very important. More people fail because they can't read the input correctly than because their logic is wrong. The compiler is strict, and the problem descriptions can be vague about the input format.<\/p>\n\n\n\n<p><strong>The Rule:<\/strong> Assume the simplest input format unless specified.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If they need a list of numbers, they'll likely provide N on the first line, followed by N numbers on subsequent lines, each on a new line.<\/li>\n\n\n\n<li>Don't try to get fancy with <code>split()<\/code> or parsing comma-separated strings unless the problem explicitly says so.<\/li>\n\n\n\n<li>Practice reading various input types: a single integer, a line of space-separated integers, an integer N followed by N lines of input, etc. This is a common failure point.<\/li>\n<\/ul>\n\n\n\n<p><strong>Pro Tip for Python Users:<\/strong> The compiler's handling of tabs versus spaces for indentation is a known issue. Use spaces for indentation to be safe. Some candidates report that tabs simply do not work correctly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"core-topics-solved-questions\">Core Topics &amp; Solved Questions<\/h2>\n\n\n\n<p>Here's a breakdown of the question types you will face. We'll go through each with examples. Focus on the logic. The implementation is just a tool.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-array-based-questions\">1. Array-Based Questions<\/h3>\n\n\n\n<p><a href=\"https:\/\/www.mygreatlearning.com\/blog\/python-array\/\">Arrays<\/a> are the bread and butter of the NQT. You are almost guaranteed to get an array question. They test your ability to manipulate a list of numbers.<\/p>\n\n\n\n<p><strong>Common Array Problems:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Finding the second largest\/smallest element.<\/li>\n\n\n\n<li>Removing duplicates from a sorted or unsorted array.<\/li>\n\n\n\n<li>Rotating an array by 'k' elements.<\/li>\n\n\n\n<li>Finding a missing number in a sequence.<\/li>\n\n\n\n<li>Sorting an array of 0s, 1s, and 2s.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"question-1-find-the-second-largest-number-in-an-array\">Question 1: Find the Second Largest Number in an Array<\/h3>\n\n\n\n<p><strong>Problem:<\/strong> Given an array of integers, find the second largest element.<\/p>\n\n\n\n<p><strong>The Logic:<\/strong><\/p>\n\n\n\n<p>Don't overthink this. You don't need to sort the whole array; that's inefficient. You only need two variables: <code>largest<\/code> and <code>second_largest<\/code>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Initialize <code>largest<\/code> and <code>second_largest<\/code> to the smallest possible integer value.<\/li>\n\n\n\n<li>Iterate through the array.<\/li>\n\n\n\n<li>For each element, check:\n<ul class=\"wp-block-list\">\n<li>If it's greater than <code>largest<\/code>, the current <code>largest<\/code> becomes the new <code>second_largest<\/code>, and this element becomes the new <code>largest<\/code>.<\/li>\n\n\n\n<li>Else, if it's greater than <code>second_largest<\/code> (but not <code>largest<\/code>), it becomes the new <code>second_largest<\/code>.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Return <code>second_largest<\/code>.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"python-solution\">Python Solution:<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ndef find_second_largest(arr):\n    if len(arr) &amp;lt; 2:\n        return &quot;Array size must be at least 2&quot;\n\n    # Use float(&#039;-inf&#039;) to avoid importing sys and handle all negatives\n    largest = float(&#039;-inf&#039;)\n    second_largest = float(&#039;-inf&#039;)\n\n    for num in arr:\n        if num &gt; largest:\n            second_largest = largest\n            largest = num\n        elif num &gt; second_largest and num != largest:\n            second_largest = num\n    \n    if second_largest == float(&#039;-inf&#039;):\n        return &quot;No second largest element exists&quot;\n    else:\n        return second_largest\n\n# How to handle input in the TCS environment\ntry:\n    n = int(input().strip())\n    arr = &#x5B;]\n    for _ in range(n):\n        arr.append(int(input().strip()))\n    \n    result = find_second_largest(arr)\n    print(result)\n\nexcept ValueError:\n    print(&quot;Invalid input&quot;)\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Why this beats sorting:<\/strong> A beginner's instinct is to do <code>list(set(arr))<\/code> , and then <code>sort()<\/code>, grabbing the second-to-last item. <strong>Do not do this.<\/strong> Sorting takes <strong>O(N log N)<\/strong> time. This single-pass solution takes <strong>O(N)<\/strong> time and <strong>O(1)<\/strong> space, which is mandatory to clear hidden test cases for large arrays.<\/li>\n\n\n\n<li>We use <code>float('-inf')<\/code> instead of importing modules. It's cleaner, standard Python practice, and properly catches arrays filled entirely with negative integers (e.g., <code>[-10, -40, -20]<\/code>).<\/li>\n\n\n\n<li>The <code>input().strip()<\/code> addition is crucial; TCS compilers often inject invisible trailing spaces that crash standard <code>int()<\/code> conversions.<\/li>\n<\/ul>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-title-link\">Python Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">In this course, you will learn the fundamentals of Python: from basic syntax to mastering data structures, loops, and functions. You will also explore OOP concepts and objects to build robust programs.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>11.5 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>51 Coding Exercises<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"question-2-remove-duplicates-from-a-sorted-array\">Question 2: Remove Duplicates from a Sorted Array<\/h3>\n\n\n\n<p><strong>Problem:<\/strong> Given a sorted array, remove the duplicates in-place such that each element appears only once. Return the new length of the array.<\/p>\n\n\n\n<p><strong>The Logic:<\/strong><\/p>\n\n\n\n<p>This is a classic two-pointer problem. Since the array is sorted, all duplicate elements will be adjacent.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use one pointer (<code>write_index<\/code>) to keep track of the position where the next unique element should be placed. Initialize it to 1 (since the first element is always unique).<\/li>\n\n\n\n<li>Use a second pointer (<code>i<\/code>) to iterate through the array from the second element (<code>i = 1<\/code>).<\/li>\n\n\n\n<li>Compare the element at <code>i<\/code> with the element at <code>i-1<\/code>.<\/li>\n\n\n\n<li>If they are different, it means you've found a new unique element. Copy it to <code>arr[write_index]<\/code> and increment <code>write_index<\/code>.<\/li>\n\n\n\n<li>If they are the same, do nothing but continue iterating with <code>i<\/code>.<\/li>\n\n\n\n<li>The final value of <code>write_index<\/code> is your new length.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"python-solution\">Python Solution:<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ndef remove_duplicates(arr):\n    if not arr:\n        return 0\n\n    write_index = 1\n    for i in range(1, len(arr)):\n        if arr&#x5B;i] != arr&#x5B;i-1]:\n            arr&#x5B;write_index] = arr&#x5B;i]\n            write_index += 1\n            \n    return write_index\n\n# Example Input Handling\ntry:\n    # Assuming input is space-separated integers on one line\n    # Note: This input style might vary. Adapt as needed.\n    input_line = input()\n    arr = list(map(int, input_line.split()))\n    \n    new_length = remove_duplicates(arr)\n    \n    # Printing the modified array up to the new length\n    for i in range(new_length):\n        print(arr&#x5B;i], end=&quot; &quot;)\n    print() # for a newline at the end\n\nexcept (ValueError, IndexError):\n    print(&quot;Invalid input format&quot;)\n\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This approach is efficient (O(n) time complexity) because it modifies the array in a single pass.<\/li>\n\n\n\n<li>It works \"in-place,\" meaning it doesn't use extra memory for another array, which is often a requirement.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-string-manipulation-questions\">2. <a href=\"https:\/\/www.mygreatlearning.com\/blog\/python-string-manipulation\/\">String Manipulation<\/a> Questions<\/h3>\n\n\n\n<p>String questions are also very common. They test your understanding of characters, <a href=\"https:\/\/www.mygreatlearning.com\/blog\/python-substring\/\">substrings<\/a>, and basic string algorithms.<\/p>\n\n\n\n<p><strong>Common String Problems:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Check if a string is a palindrome.<\/li>\n\n\n\n<li>Count vowels and consonants.<\/li>\n\n\n\n<li>Find duplicate characters.<\/li>\n\n\n\n<li>Check if two strings are anagrams.<\/li>\n\n\n\n<li>Reverse words in a sentence.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"question-3-check-if-two-strings-are-anagrams\">Question 3: Check if Two Strings are Anagrams<\/h3>\n\n\n\n<p><strong>Problem:<\/strong> Given two strings, determine if they are anagrams of each other.<\/p>\n\n\n\n<p><strong>The Logic (Optimized for Digital\/Prime Constraints):<\/strong><\/p>\n\n\n\n<p>While sorting the strings is the easiest method, it takes <strong>O(N log N)<\/strong> time. In the new TCS Advanced section, string lengths can be massive (e.g., 10^5 characters), and sorting will result in a Time Limit Exceeded (TLE) error. The optimal approach is <strong>O(N)<\/strong> time using a frequency counter (Hash Map\/Dictionary).<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>Check if the lengths are equal. If not, return False.<\/li>\n\n\n\n<li>Create an empty dictionary to count character frequencies.<\/li>\n\n\n\n<li>Loop through the first string, incrementing the count for each character.<\/li>\n\n\n\n<li>Loop through the second string, decrementing the count for each character. If a character is missing or its count drops below zero, they aren't anagrams.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"python-solution\">Python Solution:<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ndef are_anagrams(str1, str2):\n    s1 = str1.replace(&quot; &quot;, &quot;&quot;).lower()\n    s2 = str2.replace(&quot; &quot;, &quot;&quot;).lower()\n\n    if len(s1) != len(s2):\n        return False\n\n    char_counts = {}\n    \n    # Build frequency map for first string\n    for char in s1:\n        char_counts&#x5B;char] = char_counts.get(char, 0) + 1\n        \n    # Check frequencies against the second string\n    for char in s2:\n        if char not in char_counts or char_counts&#x5B;char] == 0:\n            return False\n        char_counts&#x5B;char] -= 1\n        \n    return True\n\n# Input handling\ntry:\n    string1 = input().strip()\n    string2 = input().strip()\n\n    if are_anagrams(string1, string2):\n        print(&quot;Yes&quot;)\n    else:\n        print(&quot;No&quot;)\n        \nexcept Exception:\n    print(&quot;Invalid input&quot;)\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This approach operates in pure <strong>O(N)<\/strong> time, safely passing all massive string edge cases in the Prime category.<\/li>\n\n\n\n<li>We use <code>.get(char, 0)<\/code> to avoid <code>KeyError<\/code> exceptions when building the dictionary, which is a common pitfall in high-pressure testing environments.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-number-theory-and-mathematical-problems\">3. Number Theory and Mathematical Problems<\/h3>\n\n\n\n<p>These questions involve logic based on mathematical concepts. They are less about complex <a href=\"https:\/\/www.mygreatlearning.com\/blog\/data-structure-tutorial-for-beginners\/\">data structures<\/a> and more about your problem-solving logic.<\/p>\n\n\n\n<p><strong>Common Number Theory Problems:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Check if a number is prime.<\/li>\n\n\n\n<li>Find the GCD (Greatest Common Divisor) of two numbers.<\/li>\n\n\n\n<li>Check for Armstrong or Palindrome numbers.<\/li>\n\n\n\n<li>Generate Fibonacci series.<\/li>\n\n\n\n<li>Convert between number systems (e.g., decimal to binary).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"question-4-check-for-a-prime-number\">Question 4: Check for a Prime Number<\/h3>\n\n\n\n<p><strong>Problem:<\/strong> Given an integer, determine if it is a prime number.<\/p>\n\n\n\n<p><strong>The Logic:<\/strong><\/p>\n\n\n\n<p>A prime number is a number greater than 1 that has no positive divisors other than 1 and itself.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Handle the edge cases first: numbers less than or equal to 1 are not prime. 2 is the only even prime number.<\/li>\n\n\n\n<li>If the number is even (and not 2), it's not prime. Return false.<\/li>\n\n\n\n<li>For odd numbers, you don't need to check for divisibility all the way up to the number itself. You only need to check up to its square root.<\/li>\n\n\n\n<li>Iterate from 3 up to the square root of the number, incrementing by 2 (to check only odd divisors).<\/li>\n\n\n\n<li>If you find any number that divides it evenly, it's not prime.<\/li>\n\n\n\n<li>If the loop finishes without finding any divisors, the number is prime.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"python-solution\">Python Solution:<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nimport math\n\ndef is_prime(n):\n    if n &amp;lt;= 1:\n        return False\n    if n == 2:\n        return True\n    if n % 2 == 0:\n        return False\n    \n    # Iterate from 3 up to the square root of n, only checking odd numbers\n    i = 3\n    while i * i &amp;lt;= n:\n        if n % i == 0:\n            return False\n        i += 2\n        \n    return True\n\n# Input handling\ntry:\n    num = int(input())\n    if is_prime(num):\n        print(&quot;Prime&quot;)\n    else:\n        print(&quot;Not Prime&quot;)\n        \nexcept ValueError:\n    print(&quot;Invalid input. Please enter an integer.&quot;)\n\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <code><strong>i * i &lt;= n<\/strong><\/code> condition is an optimized way of checking up to the square root of N, executing in <strong>O(\u221aN)<\/strong> time. It cleverly avoids floating-point calculations which can occasionally cause precision issues in strict testing environments.<\/li>\n\n\n\n<li><strong>2026 Prime Role Warning:<\/strong> This O(\u221aN) approach is perfect if they ask you to check <em>one<\/em> number. However, if the question asks you to \"Find all prime numbers in a range up to 100,000\" or gives you multiple queries, using this loop repeatedly will cause a Time Limit Exceeded (TLE) error. For range-based prime questions, you must learn and implement the <strong>Sieve of Eratosthenes<\/strong> algorithm, which generates primes in <strong>O(N log log N)<\/strong> time.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"4-advanced-topics-for-digital-prime-roles\">4. Advanced Topics (For Digital\/Prime Roles)<\/h3>\n\n\n\n<p>If you are targeting the 7 LPA (Digital) or 9-12 LPA (Prime) packages, the 90-minute advanced coding section will push your limits. TCS has significantly raised the bar for Prime candidates, so basic arrays won't be enough. <\/p>\n\n\n\n<p><strong>Topics to master for 2026:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Advanced Data Structures:<\/strong> Stacks, Queues, Linked Lists, Trees, and basic Graph traversals (BFS\/DFS) are highly tested.<\/li>\n\n\n\n<li><strong>Recursion &amp; Backtracking:<\/strong> Generating subsets, permutations, or solving maze-based scenario questions.<\/li>\n\n\n\n<li><strong>Sorting &amp; Searching:<\/strong> Beyond basic <a href=\"https:\/\/www.mygreatlearning.com\/blog\/bubble-sort\/\">Bubble Sort<\/a>, <a href=\"https:\/\/www.mygreatlearning.com\/blog\/insertion-sort-algorithm\/\">Insertion Sort<\/a>, you must understand the logic and implementation of <a href=\"https:\/\/www.mygreatlearning.com\/blog\/merge-sort\/\">Merge Sort<\/a>, Quick Sort, and Binary Search optimizations.<\/li>\n\n\n\n<li><strong>String Operations:<\/strong> Forward\/backward shifting, matrix operations, and complex pattern matching.<\/li>\n\n\n\n<li><strong>Dynamic Programming (DP) &amp; Greedy Algorithms:<\/strong> DP is no longer \"very unlikely.\" For the Prime role, expect 1D and 2D dynamic programming questions (e.g., optimal path calculation, knapsack variations) and greedy approach problems. Time and space complexity constraints will be tight, so O(n^2) brute-force solutions will fail hidden test cases.<\/li>\n<\/ul>\n\n\n\n<p><strong>Also Read:<\/strong> <a href=\"https:\/\/www.mygreatlearning.com\/blog\/linked-list-interview-questions\/\">Linked List Interview Questions and Answers<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"question-5-balanced-parentheses\">Question 5: Balanced Parentheses<\/h3>\n\n\n\n<p><strong>Problem:<\/strong> Given a string containing just the characters <code>(<\/code>, <code>)<\/code>, <code>{<\/code>, <code>}<\/code>, <code>[<\/code> and <code>]<\/code>, determine if the input string is valid. An input string is valid if open brackets are closed by the same type of brackets and in the correct order.<\/p>\n\n\n\n<p><strong>The Logic:<\/strong><\/p>\n\n\n\n<p>This is the classic use case for a stack.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a mapping of opening brackets to their corresponding closing brackets. e.g., <code>{'(': ')'}<\/code>.<\/li>\n\n\n\n<li>Initialize an empty stack (a list in Python can act as a stack).<\/li>\n\n\n\n<li>Iterate through the input string character by character.<\/li>\n\n\n\n<li>If the character is an opening bracket (<code>(<\/code>, <code>{<\/code>, <code>[<\/code>), push it onto the stack.<\/li>\n\n\n\n<li>If the character is a closing bracket (<code>)<\/code>, <code>}<\/code>, <code>]<\/code>):\n<ul class=\"wp-block-list\">\n<li>Check if the stack is empty. If it is, there's no matching opening bracket, so the string is invalid.<\/li>\n\n\n\n<li>Pop the top element from the stack.<\/li>\n\n\n\n<li>Check if the current closing bracket is the correct match for the popped opening bracket (using your map). If not, it's invalid.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>After the loop finishes, check if the stack is empty. If it is, all brackets were matched correctly. If it's not empty, it means there are unclosed opening brackets, so it's invalid.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"python-solution\">Python Solution:<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\ndef is_balanced(s):\n    stack = &#x5B;]\n    mapping = {&quot;)&quot;: &quot;(&quot;, &quot;}&quot;: &quot;{&quot;, &quot;]&quot;: &quot;&#x5B;&quot;}\n\n    for char in s:\n        if char in mapping: # It&#039;s a closing bracket\n            # Pop the top element from the stack if it&#039;s not empty, otherwise assign a dummy value\n            top_element = stack.pop() if stack else &#039;#&#039;\n            \n            if mapping&#x5B;char] != top_element:\n                return False\n        else: # It&#039;s an opening bracket\n            stack.append(char)\n            \n    # The string is balanced only if the stack is empty at the end\n    return not stack\n\n# Input handling\ntry:\n    expression = input()\n    if is_balanced(expression):\n        print(&quot;Balanced&quot;)\n    else:\n        print(&quot;Not Balanced&quot;)\n\nexcept Exception:\n    print(&quot;An error occurred.&quot;)\n\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The stack perfectly models the \"last-in, first-out\" nature of nested brackets. The last opening bracket you see must be the first one you close.<\/li>\n\n\n\n<li>The final <code>return not stack<\/code> is a concise way to check if the stack is empty. An empty list evaluates to <code>False<\/code>, so <code>not []<\/code> is <code>True<\/code>.<\/li>\n<\/ul>\n\n\n\n<p><strong>Also Read: <\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/tcs-interview-questions\/\">TCS Normal Interview Questions and Answers<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/tcs-aptitude-questions-answers\/\">TCS Aptitude Questions and Answers<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/accenture-coding-questions-solutions\/\">Accenture Coding Questions and Solutions (with code)<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"final-strategy-no-surprises\">Final Strategy: No Surprises<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Understand the Scoring Game:<\/strong> There is <strong>no negative marking<\/strong> this year. Attempt every single question in the Foundation and Advanced sections.<\/li>\n\n\n\n<li><strong>Practice On-Screen Problem Solving:<\/strong> Since physical paper is banned, practice solving complex logic problems on your computer using a digital notepad before you write the actual code.<\/li>\n\n\n\n<li><strong>Master Input\/Output:<\/strong> Write code specifically to handle different, vague input formats directly from <code>stdin<\/code>. Don't rely on auto-complete IDEs. This remains the #1 reason strong coders fail the NQT.<\/li>\n\n\n\n<li><strong>Time Management (90 Minutes for 2 Codes):<\/strong> You have a shared 90 minutes for the two coding questions. Secure the easier one completely first to lock in your Digital chances. If you get stuck on the harder one, implement a brute-force approach. Passing 5 out of 14 hidden test cases is vastly better than passing 0.<\/li>\n\n\n\n<li><strong>Language Choice:<\/strong> Use what you know best, but C++ is highly recommended by recent candidates for its performance speed and reliable behavior in the TCS iON environment, which easily clears tight time complexities where Python sometimes lags.<\/li>\n\n\n\n<li><strong>Don't Panic &amp; Don't Look Down:<\/strong> Stay calm, keep your eyes on the screen to avoid AI warnings, and double-check your input handling if your logic seems flawless but the tests are failing.<\/li>\n<\/ul>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/data-structures-and-algorithms-with-c\" class=\"courses-cta-title-link\">C++ Data Structures and Algorithms Course Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master DSA (Data Structures and Algorithms) with C++. Build coding skills in arrays, trees, graphs, heaps, sorting, searching, hashing, and algorithm analysis for interviews.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>Intermediate Level<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>9.17 hrs<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/data-structures-and-algorithms-with-c\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>Master the TCS NQT coding section with this practical guide. Learn the key question patterns, essential problem-solving techniques, and how to handle tricky input formats for success in the test.<\/p>\n","protected":false},"author":41,"featured_media":111356,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36820,36800],"content_type":[],"class_list":["post-111354","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-it-interview","tag-it-jobs"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>TCS NQT Coding Questions and Answers (with code)<\/title>\n<meta name=\"description\" content=\"Master the TCS NQT coding section with this practical guide. Learn the key question patterns, essential problem-solving techniques, and how to handle tricky input formats for success in the test.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"TCS NQT Coding Questions and Answers (with code)\" \/>\n<meta property=\"og:description\" content=\"Master the TCS NQT coding section with this practical guide. Learn the key question patterns, essential problem-solving techniques, and how to handle tricky input formats for success in the test.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-28T08:49:44+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/08\/tcs-nqt-questions.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1408\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-nqt-coding-questions-answers\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-nqt-coding-questions-answers\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"TCS NQT Coding Questions and Answers (with code)\",\"datePublished\":\"2025-08-28T08:49:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-nqt-coding-questions-answers\\\/\"},\"wordCount\":2089,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-nqt-coding-questions-answers\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/08\\\/tcs-nqt-questions.webp\",\"keywords\":[\"IT Interview\",\"IT Jobs\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-nqt-coding-questions-answers\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-nqt-coding-questions-answers\\\/\",\"name\":\"TCS NQT Coding Questions and Answers (with code)\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-nqt-coding-questions-answers\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-nqt-coding-questions-answers\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/08\\\/tcs-nqt-questions.webp\",\"datePublished\":\"2025-08-28T08:49:44+00:00\",\"description\":\"Master the TCS NQT coding section with this practical guide. Learn the key question patterns, essential problem-solving techniques, and how to handle tricky input formats for success in the test.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-nqt-coding-questions-answers\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-nqt-coding-questions-answers\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-nqt-coding-questions-answers\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/08\\\/tcs-nqt-questions.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/08\\\/tcs-nqt-questions.webp\",\"width\":1408,\"height\":768,\"caption\":\"TCS NQT Coding Questions and Answers (with code)\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/tcs-nqt-coding-questions-answers\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"TCS NQT Coding Questions and Answers (with code)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"TCS NQT Coding Questions and Answers (with code)","description":"Master the TCS NQT coding section with this practical guide. Learn the key question patterns, essential problem-solving techniques, and how to handle tricky input formats for success in the test.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/","og_locale":"en_US","og_type":"article","og_title":"TCS NQT Coding Questions and Answers (with code)","og_description":"Master the TCS NQT coding section with this practical guide. Learn the key question patterns, essential problem-solving techniques, and how to handle tricky input formats for success in the test.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2025-08-28T08:49:44+00:00","og_image":[{"width":1408,"height":768,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/08\/tcs-nqt-questions.webp","type":"image\/webp"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"TCS NQT Coding Questions and Answers (with code)","datePublished":"2025-08-28T08:49:44+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/"},"wordCount":2089,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/08\/tcs-nqt-questions.webp","keywords":["IT Interview","IT Jobs"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/","url":"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/","name":"TCS NQT Coding Questions and Answers (with code)","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/08\/tcs-nqt-questions.webp","datePublished":"2025-08-28T08:49:44+00:00","description":"Master the TCS NQT coding section with this practical guide. Learn the key question patterns, essential problem-solving techniques, and how to handle tricky input formats for success in the test.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/08\/tcs-nqt-questions.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/08\/tcs-nqt-questions.webp","width":1408,"height":768,"caption":"TCS NQT Coding Questions and Answers (with code)"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/tcs-nqt-coding-questions-answers\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"TCS NQT Coding Questions and Answers (with code)"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/08\/tcs-nqt-questions.webp",1408,768,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/08\/tcs-nqt-questions-150x150.webp",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/08\/tcs-nqt-questions-300x164.webp",300,164,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/08\/tcs-nqt-questions-768x419.webp",768,419,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/08\/tcs-nqt-questions-1024x559.webp",1024,559,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/08\/tcs-nqt-questions.webp",1408,768,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/08\/tcs-nqt-questions.webp",1408,768,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/08\/tcs-nqt-questions-640x768.webp",640,768,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/08\/tcs-nqt-questions-96x96.webp",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/08\/tcs-nqt-questions-150x82.webp",150,82,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Master the TCS NQT coding section with this practical guide. Learn the key question patterns, essential problem-solving techniques, and how to handle tricky input formats for success in the test.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/111354","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=111354"}],"version-history":[{"count":11,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/111354\/revisions"}],"predecessor-version":[{"id":116655,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/111354\/revisions\/116655"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/111356"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=111354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=111354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=111354"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=111354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}