Home Icon Home Get Hired TCS Digital Coding Questions: Top 5 Coding Questions & Solutions

TCS Digital Coding Questions: Top 5 Coding Questions & Solutions

Learn TCS Digital coding questions by solving the top 5 coding questions with detailed solutions in C++, Python, and Java. Enhance your coding skills now.
Kaihrii Thomas
Schedule Icon 0 min read
TCS Digital Coding Questions: Top 5 Coding Questions & Solutions
Schedule Icon 0 min read

Table of content: 

  • Digital Coding Questions: Topics Covered
  • TCS Digital Previous Year Coding Questions
  • Top 5 Digital Coding Questions with Solution
  • Digital Advanced Coding Questions
  • TCS Digital Coding Round Questions
  • Digital Coding Questions for Freshers
  • How to Prepare for TCS Digital Coding Exam?
  • Conclusion
  • Frequently Asked Questions (FAQs)
expand icon

TCS Digital is a premium role offered by Tata Consultancy Services (TCS) that focuses on digital technologies. To secure this role, candidates must go through a rigorous selection process, including a challenging coding round. This guide provides a comprehensive overview of TCS Digital coding questions, covering various aspects such as previous year questions, advanced coding problems, and the types of questions to expect.

TCS Digital Coding Round Overview

The coding round is a crucial stage in the TCS Digital hiring process. It typically consists of 2-3 questions that test the candidate's problem-solving abilities, coding skills, and algorithmic knowledge. The time duration for this round is usually between 60 to 90 minutes.

Category Details
Number of Questions 2-3 coding problems
Duration 60 to 90 minutes
Difficulty Level Moderate to Advanced
Languages Allowed C, C++, Java, Python, etc.
Focus Areas Data Structures, Algorithms, Dynamic Programming

Digital Coding Questions: Topics Covered

The questions in TCS Digital coding assessments cover a wide range of programming topics. Here's a breakdown of the topics and the types of questions you may encounter:

Topic Description Example Questions
Data Structures Implementing and manipulating data structures such as arrays, linked lists, stacks, and trees. Reverse a linked list, Find a cycle in a graph
Algorithms Questions involving searching, sorting, and optimization techniques. Quick Sort, Binary Search, Dijkstra's Algorithm
Dynamic Programming (DP) Problems requiring memoization or tabulation to optimize solutions. Knapsack problem, Longest Common Subsequence
Greedy Algorithms Optimization problems are solved through the greedy approach. Activity selection, Fractional Knapsack
String Manipulation String-related problems such as pattern matching and transformations. Palindrome check, Anagram detection
Recursion & Backtracking Recursive problems that involve decision trees and combinatorial searches. N-Queens, Subset Sum problem

TCS Digital Previous Year Coding Questions

TCS Digital often repeats coding patterns from previous years with slight modifications. Here are some examples of the previous year's coding questions:

Question Type Topic Difficulty
Write a program to find the shortest path in a weighted graph using Dijkstra's algorithm. Algorithm Graph Theory Advanced
Given a matrix, rotate it 90 degrees clockwise. Data Structures Matrix Manipulation Moderate
Implement a function to check if two strings are anagrams of each other. String Manipulation Sorting, String Easy
Solve the 0/1 Knapsack problem using dynamic programming. Dynamic Programming DP, Recursion Advanced
Find all permutations of a given string using recursion. Backtracking String, Recursion Moderate

Enhance your coding skills by practicing coding questions across various levels. Click here to start your coding journey and master programming!

Top 5 Digital Coding Questions with Solution

Problem Statement 1

One day, Jack finds a string of characters. He is very keen to arrange them in reverse order, i.e., the first characters become the last characters, the second characters become the second-last characters, and so on.

Now he wants your help  to find the kth character from the new string formed after reverse the original string.

Note: String contains only lowercase Latin letters.

Input Format

The first line contains two integers n, k — the length of array and the value of k respectively.

The second line contains a string containing n characters.

Output Format

Print a single line containing the kth character of the string.

Constraints

1 ≤ k ≤ n≤ 10^6

Testcase Input

5 2

abdfa

Testcase Output

f

Solution 1: C++

Solution 1: Java

Solution 3: Python 

Problem Statement 2

Alice challenged Bob to write the same word as his on a typewriter. Both are kids and are making some mistakes in typing and are making use of the ‘#’ key on a typewriter to delete the last character printed on it.

An empty text remains empty even after backspaces. 

Input Format

The first line contains a string typed by Bob.

The second line contains a string typed by Alice.

Output Format

The first line contains ‘YES’ if Alice is able to print the exact words as Bob , otherwise ‘NO’.

Constraints

1 <= Bob.length

Alice.length <= 100000

Bob and Alice only contain lowercase letters and '#' characters.

Testcase Input

ab#c

ad#c

Testcase Output

YES

Solution 1: C++

Solution 2: Python 

Solution 3: Java 

Problem Statement 3

Ram gave Shyaam a challenge, he gave shyaam the head of a linked list, and an integer k. He asked Shyaam to swap the values of the Kth node from the beginning and the Kth node from the end (the list is 1-indexed).

Note: The number of nodes in the list is N.

Input Format

The first line contains an integer N, representing the number of nodes in the linked list.

The second line contains N space-separated integers, each representing the value of a node in the linked list.

The third line contains an integer K, indicating the positions of the nodes to be swapped.

Output Format

Output the linked list after swapping the values of the two specified nodes.

Constraints

1 <= K <= N <= 10^5

0 <= Node.val <= 10^2

Testcase Input

5

1 2 3 4 5

2

Testcase Output

1 4 3 2 5

Solution 1: Java

Solution 2: C++

Solution 3: Python 

Problem Statement 4

There are n spaceship at given lightyears away from the earth and traveling to reach a distant star system at k lightyear away from earth. You are given two integer arrays, position and speed, both of length n, where

P[i] is the current distance of the ith spaceship

S[i] is the speed of the ith spaceship in lightyears per year.

As the spaceships travel toward the star system, an interesting phenomenon occurs: when a faster spaceship catches up to a slower one, it reduces its speed to match the slower spaceship's speed, forming a fleet. A fleet is a group of one or more spaceships that travel together at the same speed.

Given this information, determine the number of distinct spacecraft fleets that will arrive at the destination star system. A fleet is considered distinct if no other fleet arrives at the destination at the same time while traveling together.

Input Format

The first line contains an integer 'n', representing the total number of spaceships.

The second line contains an integer 'k', representing the distance of the star system from Earth.

The third line contains 'n' space-separated integers denoting the current distance of the i-th spaceship from Earth.

The fourth line contains 'n' space-separated integers denoting the speed of the i-th spaceship.

Output Format

Return the number of spacecraft fleets that will arrive at the destination.

Constraints

1 <= n <= 10^5

0 < k <= 10^6

0 <= P[i] < target

0 < S[i] <= 10

Testcase Input

4

14

10 8 5 3

2 4 1 3

Testcase Output

2

Solution 1: Python 

Solution 2: C++

Solution 3: Java

Problem Statement 5

You are provided with a 2D array(N*M). Your task is to create an ArrayList of Node objects, where each row of the 2D array corresponds to one entry in the ArrayList. After that, a doubly-linked list is constructed, arranging nodes first by even indices from the ArrayList, followed by the odd indices.

Input Format

The first line contains an integer N, representing the size of the array row.

The second line contains an integer M, representing the size of array col.

The third line contains an array.

Output Format

return the linked list

Constraints

1 <= N < 10^2

1 <= M < 10^2

Testcase Input

4

6

2 4 5 3 6 7

5 3 6 3 6 7

3 6 7 2 6 8

4 2 1 6 8 9

Testcase Output

2 <---> 4 <---> 5 <---> 3 <---> 6 <---> 7 <---> 3 <---> 6 <---> 7 <---> 2 <---> 6 <---> 8 <---> 5 <---> 3 <---> 6 <---> 3 <---> 6 <---> 7 <---> 4 <---> 2 <---> 1 <---> 6 <---> 8 <---> 9 <---> null

Solution 1: Java

Solution 2: C++

Solution 3: Python 

Digital Advanced Coding Questions

TCS Digital coding questions for advanced levels test not only your knowledge but also your efficiency in solving complex problems within tight time constraints. These questions often involve multiple layers of logic and optimization techniques. Here are a few sample advanced coding problems:

Problem Topic Approach
Implement a Least Recently Used (LRU) Cache using linked lists and hashmaps. Data Structures (Linked List, HashMap) Efficient use of space and time
Find the longest increasing subsequence in a given array. Dynamic Programming Memoization, Recursion
Given a binary tree, convert it into its mirror image. Trees Recursive Tree Manipulation
Implement a system to schedule jobs on multiple processors using priority queues. Greedy Algorithms Queue Manipulation, Optimization
Design an algorithm to find the maximum profit that can be made by buying and selling stocks. Dynamic Programming, Greedy Max Profit, Min Cost Calculation

TCS Digital Coding Round Questions

The coding round for TCS Digital typically involves a mix of medium to high difficulty problems. Here is an example format of a typical coding round:

Question Type Sample Question Solution Approach
Medium-Level Algorithm Find the second largest element in an unsorted array. Use sorting or linear scan
Advanced-Data Structure Implement a priority queue using a min-heap. Heap-based operations
Dynamic Programming Find the longest palindromic subsequence in a string. DP table with memoization
Greedy Algorithm Schedule tasks with given deadlines and maximize profit. Greedy method with sorting
String Manipulation Find the smallest window in a string containing all characters of another string. Sliding window technique

Digital Coding Questions for Freshers

While the coding questions for TCS Digital are challenging, they are also solvable with proper preparation. Freshers are typically expected to demonstrate a strong grasp of fundamental algorithms and data structures. Commonly asked coding questions for freshers include:

Question Topic Difficulty
Implement binary search on a sorted array. Searching Algorithm Easy
Write a function to check if a string is a palindrome. String Manipulation Easy
Reverse the elements of a linked list. Linked List Moderate
Sort an array using merge sort. Sorting Algorithms Moderate
Find the number of ways to reach the nth stair if you can climb either 1 or 2 steps at a time. Dynamic Programming Moderate

How to Prepare for TCS Digital Coding Exam?

To succeed in TCS Digital coding rounds, you need to focus on understanding and practising core topics:

Preparation Strategy Description
Master Data Structures & Algorithms Study data structures like arrays, linked lists, trees, and algorithms such as sorting, searching, and graph traversal.
Practice Dynamic Programming Solve DP-based problems to build optimization skills.
Time Management Practice solving problems under timed conditions.
Focus on Optimization Practice reducing time and space complexity for efficient solutions.

Disclaimer: While we have gathered as much information from TCS’s official website as possible, we have also included sources gathered from available online sources. Therefore, readers are advised to check and stay updated with the official website.

Conclusion

TCS Digital coding questions challenge candidates on multiple levels, requiring proficiency in algorithms, data structures, dynamic programming, and more. Whether you're a fresher or an experienced professional, thorough preparation and continuous practice of advanced coding problems are essential for cracking the TCS Digital coding round.

Use the past questions as practice and focus on time-bound solving to improve speed and accuracy. By mastering the essential topics and practising a variety of coding problems, you can significantly increase your chances of securing a role in TCS Digital.

Frequently Asked Questions (FAQs)

1. What is the difficulty level of coding questions in the TCS Digital exam?

The coding questions in TCS Digital range from moderate to advanced. They often test knowledge of algorithms, data structures, and problem-solving with an emphasis on optimization.

2. Which programming languages can I use in the TCS Digital coding round?

You can choose from popular languages such as C, C++, Java, Python, and sometimes JavaScript, depending on the platform used for the coding assessment.

3. How many coding questions are asked in the TCS Digital exam?

Typically, the TCS Digital exam includes 2-3 coding questions to be solved within 60 to 90 minutes.

4. What are the most common topics for TCS Digital coding questions?

The most common topics include dynamic programming, string manipulation, sorting and searching algorithms, graph theory, and data structures like arrays, trees, and linked lists.

5. How can I prepare for the TCS Digital advanced coding questions?

To prepare for advanced coding questions, focus on solving complex problems related to dynamic programming, graph algorithms, and system design. Practising on coding platforms like LeetCode and Codeforces can also be helpful.

Suggested reads:

Edited by
Kaihrii Thomas
Associate Content Writer

Instinctively, I fall for nature, music, humour, reading, writing, listening, travelling, observing, learning, unlearning, friendship, exercise, etc., all these from the cradle to the grave- that's ME! It's my irrefutable belief in the uniqueness of all. I'll vehemently defend your right to be your best while I expect the same from you!

Tags:
Placement

Comments

Add comment
No comments Image No comments added Add comment
Powered By Unstop Logo
Best Viewed in Chrome, Opera, Mozilla, EDGE & Safari. Copyright © 2024 FLIVE Consulting Pvt Ltd - All rights reserved.