TCS Digital Coding Questions

TCS Digital Coding Questions : This section focuses on TCS Digital coding questions with Answers. These programming questions are asked in previous TCS Digital Exams and will help you to prepare for upcoming TCS Digital exam.


TCS Digital Coding Question - 1

Problem Description: Given an array Arr[ ] of N integers and a positive integer K. The task is to cyclically rotate the array clockwise by K. Keep the first of the array unaltered.
Test Case: Input :
5 — Value of N
{10, 20, 30, 40, 50} — Element of Arr[ ]
2 — Value of K
Output :
40 50 10 20 30

#include<bits/stdc++.h>
using namespace std;

vector<int> rotate(int nums[], int n, int k) {

    if (k > n)
        k = k % n;

    vector 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 Array[] = { 1, 2, 3, 4, 5 };
    int N = sizeof(Array) / sizeof(Array[0]);
    int K = 2;

    vector<int> ans = rotate(Array, N, K);
    for (int i = 0; i < N; ++i) {
        cout << ans[i] << ' ';
    }
}

TCS Digital Coding Question - 2

Problem Description:
Given two non-negative integers n1 and n2, where n1

For example:
Suppose n1=11 and n2=15.
There is the number 11, which has repeated digits, but 12, 13, 14 and 15 have no repeated digits. So, the output is 4.
Case 1:
Input:
11 — Vlaue of n1
15 — value of n2

Output:
4

#include<bits/stdc++.h>
using namespace std;

int find(int n1, int n2) {
    int count = 0;
    for (int i = n1 ; i <= n2 ; i++) {
        int num = i;

        vector<bool> visited;
        visited.assign(10, false);

        while (num > 0) {
            if (visited[num % 10] == true)
                break;
            visited[num % 10] = true;
            num /= 10;
        }

        if (num == 0)
            count++;
    }
    return count;
}

int main()
{
    int n1 = 101, n2 = 200;
    cout << find(n1, n2);
}


Other Programming Questions


1. Program to reverse a string.
2. Program to check whether the given number is palindrome or not.
3. Program to check whether the given number is prime number or not.
4. Program to check whether the given year is leap year or not.
5. Program to print fibonacci series.
6. Program to find GCD of two numbers.
7. Program to find factorial of a number.
8. Program to check armstrong number.
9. Program to swap two numbers without using temporary variable.
10. Program to check whether the number is even or odd.