Preparing for technical interviews remains essential for aspiring software developers to showcase their skills. For those aiming to excel in the TCS Digital interview process, mastering coding is essential. Candidates should focus on understanding core concepts, practicing coding problems, and developing effective strategies confidently to tackle questions. Engaging in mock interviews and familiarizing themselves with common problem types can significantly enhance their readiness and performance. In this blog, we’ll explore the types of coding questions asked, the best strategies for coding practice for TCS Digital, and tips to tackle coding questions in TCS Digital interviews.
Whether you’re preparing for the TCS Digital exam or an interview, understanding these coding questions will significantly enhance your chances of success.
What is TCS Digital?
TCS Digital is a recruitment drive specifically prepared to attract graduates with strong technical capabilities. The program evaluates candidates through various stages, including aptitude tests, technical interviews, and coding assessments. Success in these rounds often depends on a candidate's ability to solve complex problems efficiently, making coding for TCS Digital an essential skill for applicants.
Types of Coding Problems in TCS Digital
The types of coding problems in TCS Digital cover the following topics:
- Arrays
- Linked Lists
- Trees
- Graphs
- Sorting Algorithms
- Optimization Problems
- Subproblems
- Locally Optimal Choices
- String Processing
- Pattern Matching
- Number Theory
- Mathematical Concepts
Sample Questions and Answers Asked in TCS Digital Coding Test
Here, are the sample questions asked in the TCS Digital exam:
1. Given an array Arr[] of N integers and a positive integer K, cyclically rotate the array clockwise by K.
Example
Input
5
10 20 30 40 50
2
Output
40 50 10 20 30
C++
#include <iostream>
#include <vector>
using namespace std;
vector<int> rotate(int nums[], int n, int k) {
k = k % n;
vector<int> ans(n);
for (int i = 0; i < k; i++) {
ans[i] = nums[n - k + i];
}
int index = 0;
for (int i = k; i < n; i++) {
ans[i] = nums[index++];
}
return ans;
}
int main() {
int N, K;
cin >> N;
int Array[N];
for (int i = 0; i < N; ++i) {
cin >> Array[i];
}
cin >> K;
vector<int> ans = rotate(Array, N, K);
for (int i = 0; i < N; ++i) {
cout << ans[i] << ' ';
}
}
Java
import java.util.Scanner;
public class RotateArray {
public static int[] rotate(int[] nums, int k) {
int n = nums.length;
k = k % n;
int[] ans = new int[n];
for (int i = 0; i < k; i++) {
ans[i] = nums[n - k + i];
}
for (int i = k; i < n; i++) {
ans[i] = nums[i - k];
}
return ans;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int[] arr = new int[N];
for (int i = 0; i < N; i++) {
arr[i] = scanner.nextInt();
}
int k = scanner.nextInt();
int[] rotated = rotate(arr, k);
for (int num : rotated) {
System.out.print(num + " ");
}
scanner.close();
}
}
Python
def rotate(arr, k):
n = len(arr)
k = k % n
return arr[-k:] + arr[:-k]
N = int(input())
arr = list(map(int, input().split()))
K = int(input())
rotated = rotate(arr, K)
print(' '.join(map(str, rotated)))
2. Given two non-negative integers n1 and n2, count how many numbers in the range [n1, n2] do not have repeated digits.
Example
Input
11
15
Output
4
C++
#include <iostream>
#include <vector>
using namespace std;
bool hasRepeatedDigits(int num) {
vector<bool> visited(10, false);
while (num > 0) {
int digit = num % 10;
if (visited[digit]) return false;
visited[digit] = true;
num /= 10;
}
return true;
}
int countUniqueDigits(int n1, int n2) {
int count = 0;
for (int i = n1; i <= n2; i++) {
if (hasRepeatedDigits(i)) count++;
}
return count;
}
int main() {
int n1, n2;
cin >> n1 >> n2;
cout << countUniqueDigits(n1, n2);
}
Java
import java.util.Scanner;
public class UniqueDigits {
public static boolean hasRepeatedDigits(int num) {
boolean[] visited = new boolean[10];
while (num > 0) {
int digit = num % 10;
if (visited[digit]) return false;
visited[digit] = true;
num /= 10;
}
return true;
}
public static int countUniqueDigits(int n1, int n2) {
int count = 0;
for (int i = n1; i <= n2; i++) {
if (hasRepeatedDigits(i)) count++;
}
return count;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n1 = scanner.nextInt();
int n2 = scanner.nextInt();
System.out.println(countUniqueDigits(n1, n2));
scanner.close();
}
}
Python
def has_repeated_digits(num):
visited = [False] * 10
while num > 0:
digit = num % 10
if visited[digit]:
return False
visited[digit] = True
num //= 10
return True
def count_unique_digits(n1, n2):
count = 0
for i in range(n1, n2 + 1):
if has_repeated_digits(i):
count += 1
return count
n1, n2 = map(int, input().split())
print(count_unique_digits(n1, n2))
3. Given a string, split it into exactly 3 palindromic substrings.
Example
Input
nayannamantenet
Output
nayan
naman
tenet
C++
#include <iostream>
#include <string>
using namespace std;
bool isPalindrome(const string& s) {
return s == string(s.rbegin(), s.rend());
}
void findPalindromes(const string& str) {
int len = str.length();
for (int i = 1; i < len - 1; i++) {
string str1 = str.substr(0, i);
if (isPalindrome(str1)) {
for (int j = 1; j < len - i; j++) {
string str2 = str.substr(i, j);
string str3 = str.substr(i + j);
if (isPalindrome(str2) && isPalindrome(str3)) {
cout << str1 << "\n" << str2 << "\n" << str3 << endl;
return;
}
}
}
}
cout << "Impossible" << endl;
}
int main() {
string str;
cin >> str;
findPalindromes(str);
}
Java
import java.util.Scanner;
public class PalindromeSplit {
public static boolean isPalindrome(String s) {
return s.equals(new StringBuilder(s).reverse().toString());
}
public static void findPalindromes(String str) {
int len = str.length();
for (int i = 1; i < len - 1; i++) {
String str1 = str.substring(0, i);
if (isPalindrome(str1)) {
for (int j = 1; j < len - i; j++) {
String str2 = str.substring(i, i + j);
String str3 = str.substring(i + j);
if (isPalindrome(str2) && isPalindrome(str3)) {
System.out.println(str1);
System.out.println(str2);
System.out.println(str3);
return;
}
}
}
}
System.out.println("Impossible");
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.next();
findPalindromes(str);
scanner.close();
}
}
Python
def is_palindrome(s):
return s == s[::-1]
def find_palindromes(s):
length = len(s)
for i in range(1, length - 1):
str1 = s[:i]
if is_palindrome(str1):
for j in range(1, length - i):
str2 = s[i:i+j]
str3 = s[i+j:]
if is_palindrome(str2) and is_palindrome(str3):
print(str1)
print(str2)
print(str3)
return
print("Impossible")
s = input()
find_palindromes(s)
4. Given a range [low, high], select K numbers from the range such that their sum is even.
Example
Input
4 5
3
Output
4
C++
#include <iostream>
using namespace std;
#define mod 1000000007
long long countPermutations(long long low, long long high, long long k) {
long long even = (high / 2) - ((low - 1) / 2);
long long odd = (high - low + 1) - even;
long long evenCount = 1;
long long oddCount = 1;
for (long long i = 0; i < k; i++) {
if (i % 2 == 0) {
evenCount = (evenCount * even) % mod;
} else {
oddCount = (oddCount * odd) % mod;
}
}
return (evenCount + oddCount) % mod;
}
int main() {
long long low, high, k;
cin >> low >> high >> k;
cout << countPermutations(low, high, k);
}
Java
import java.util.Scanner;
public class CountEvenPermutations {
static final int MOD = 1000000007;
public static long countPermutations(long low, long high, long k) {
long even = (high / 2) - ((low - 1) / 2);
long odd = (high - low + 1) - even;
long evenCount = 1;
long oddCount = 1;
for (long i = 0; i < k; i++) {
if (i % 2 == 0) {
evenCount = (evenCount * even) % MOD;
} else {
oddCount = (oddCount * odd) % MOD;
}
}
return (evenCount + oddCount) % MOD;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long low = scanner.nextLong();
long high = scanner.nextLong();
long k = scanner.nextLong();
System.out.println(countPermutations(low, high, k));
scanner.close();
}
}
Python
def count_permutations(low, high, k):
mod = 1000000007
even = (high // 2) - ((low - 1) // 2)
odd = (high - low + 1) - even
even_count = 1
odd_count = 1
for i in range(k):
if i % 2 == 0:
even_count = (even_count * even) % mod
else:
odd_count = (odd_count * odd) % mod
return (even_count + odd_count) % mod
low, high, k = map(int, input().split())
print(count_permutations(low, high, k))
5. Given a string, find the first non-repeating character.
Example
Input
ccbp
Output
b
C++
#include <iostream>
#include <unordered_map>
using namespace std;
char firstUniqueChar(const string& str) {
unordered_map<char, int> charCount;
for (char ch : str) {
charCount[ch]++;
}
for (char ch : str) {
if (charCount[ch] == 1) {
return ch;
}
}
return '-'; // or any indication of no unique character
}
int main() {
string str;
cin >> str;
cout << firstUniqueChar(str);
}
Java
import java.util.HashMap;
import java.util.Scanner;
public class UniqueCharacter {
public static char firstUniqueChar(String str) {
HashMap<Character, Integer> charCount = new HashMap<>();
for (char ch : str.toCharArray()) {
charCount.put(ch, charCount.getOrDefault(ch, 0) + 1);
}
for (char ch : str.toCharArray()) {
if (charCount.get(ch) == 1) {
return ch;
}
}
return '-'; // or any indication of no unique character
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.next();
System.out.println(firstUniqueChar(str));
scanner.close();
}
}
Python
from collections import Counter
def first_unique_char(s):
char_count = Counter(s)
for ch in s:
if char_count[ch] == 1:
return ch
return '-' # or any indication of no unique character
s = input()
print(first_unique_char(s))
Tips for Cracking TCS Digital Coding Round
Here, are the tips to clear TCS Digital Coding Round:
- Make sure you have a strong understanding of data structures and algorithms.
- Use platforms like LeetCode, HackerRank, or CodeSignal to practice.
- During the exam, allocate time wisely to each question based on difficulty.
- Always look for ways to optimize your code for better performance.
- Engage in mock interviews to simulate the coding interview environment.
Conclusion
In conclusion, preparing for TCS Digital coding questions requires dedication and strategic practice. By understanding the types of problems commonly asked, familiarizing yourself with sample questions, and using effective study techniques, candidates can significantly enhance their chances of success. TCS seeks innovative thinkers who can tackle complex challenges, and a strong coding foundation is essential to impress recruiters.
Frequently Asked Questions
1. Is there an interview after the coding test?
Yes, typically, after passing the coding test, candidates may go through one or more technical interviews, which may include discussions on their solutions and general technical knowledge.
2. Can I use online resources during the coding test?
No. Candidates are expected to solve the problems using their knowledge and skills without external help or resources.