TCS Digital Coding Questions Solved : 27 Sept 2021

TCS Digital Coding Questions

This blog contains TCS DCA (Digital Capability Assessment) Questions that were asked on 27th September 2021.

Please find the questions asked on TCS DCA 28th September 2021 of the first slot from here and the second slot from here.

Below were the list of the questions that were asked, please visit each question and if you know any other way to solve the problem then please let us know in the comment section or mail us at technonamecontact@gmail.com.

Question 1 :

Let us find out whether the sum of the digits of the given positive integer number N is UNO or not. Given a positive integer number N, reduce the number of digits of N by computing the sum of all the digits to get a new number. If this new number exceeds 9, then sum the digits of this new number to get another number and continue this way until a single digit value is obtained as the ‘digit sum’. The task here is to find out whether the result of the digit sum done this way is ‘1’ or not.

If the digit sum result is 1, display a message UNO If the digit sum is not 1, display a message NOT UNO

Example :
Input:
51112 –Value of N

5+1+1+1+2 we get 10. Adding the digits again 1+0 we get the digit sum = 1 , so therefore output will be “UNO”

Input Format for Testing
The candidate must write the code to accept one input which Accept value for N (positive integer number)
Output Format for Testing
The output should print the message given in the problem statement (check the output in above example)

Solution

//Solution by Technoname.com

#include <stdio.h>

void main()
{
    int n,r,sum=0;
    scanf("%d",&n);
    while(n>0)
    {
        r=n%10;
        sum=sum+r;
        n=n/10;
    }
    if(sum%9==1)
    {
        printf("UNO");
    }
    else
    {
        printf("NOT UNO");
    }
}

Question 2 :

Most modern aircrafts are equipped with an autopilot system – one of the most useful features in fighter jets. In the beta testing of autopilot mode, one of the inputs is a string of literals containing the directions, which is fed into the flight computer before the take-off. The jet plane is put on an auto-landing mode that enables the plane to land automatically once all the directions in the string are complete Given the directions in the string str, the task here is to find out whether the jet plane returns to the same returns to the same
position on the base where it took off.

  • Each direction in the string changes at an interval of 1 minute(1< =i<= N), where N is the number of directions in the input string
  • The directions are North (N), South(S), West(W) and East(E)
  • Display a message “Returned successfully” if the plane returns to the starting position.
  • Display a message “Not returned successfully” if the plane does not return to the starting position

Example 1:
Input
NESW-Value of str
Output
Returned successfully

Example 2:
Input: NNWESW-Value of str
Output:
Not returned successfully

Solution

//Solution by Technoname.com

import java.util.Scanner;

public class Technoname
{

	public static void main(String[] args)
	{

		Scanner sc = new Scanner(System.in); 
		String s =sc.nextLine();

		int N = 0, E=0, W= 0, S= 0 ,i; 
		
		for (i=0;i<s.length();i++)
		{

			if(s.charAt(i)=='N') 
			{
				  N++;
			}
			if(s.charAt(i)=='E')
			{
				E++;
			}
			if(s.charAt(i)=='W')
			{
				W++;
			}
			if(s.charAt(i)=='S')
			{
				S++;
			}
		}
		
		if( N==S && E==W )
		{
		System.out.println("Returned successfully");
		}
		else 
		{
			System.out.println("Not Returned successfully");
		}

	}
}

Question 3 :

A ‘coin vend’ kiosk is installed all the major metro stations The machine allows one to obtain cash of ‘R’ rupees in exchange for coins.
The machine operates with the following conditions:
Only coins of denomination 1 rupee and 22 rupee can be exchanged.
Coins of denomination 2 rupees should not be inserted successively twice.
The task here to find all the possible combinations of the coins that can be inserted to get rupees from the kiosk Say, R=1, then only one coin of 1 rupee can be inserted to get 1 rupee

Example 1:
Input:
3- Value of R
Output:
3-Different ways to insert the coins to get ‘R’ rupees

Explanation:

The possible ways of inserting 1 rs and 1 rs coins for 3 rs in cash are
Way 1: (1,1,1)

Way 2 ‘: (2, 1)

Way 3 : (1, 2)

Example 2 :

Input:
5- Value of R
Output:
6-Different ways to insert the coins to get ‘R’ rupees

Explanation:

Way 1: (1,1,1,1,1)
Way 2 : (2,1,1,1)
Way 3 : (1,1,1,2)

Way 4 : (1,1.2.1)
Way 5 : (1.2,1,1)

Way 6 : (2,1,2)

Constraints:

●0<R <= 50


Input format for testing
The candidate has to write the code to accept 1 input -Accept value for N(positive integer number)
Output format for testing
The output should be a positive integer number (Check the output in Example 1 and Example 2)

Solution

//Solution by Technoname.com

import java.util.Scanner;
class Technoname {
    static int CountCoin(int n)
    {
        if (n == 0) {
            return 1;
        }
        if (n == 1) {
            return 1;
        }
        if (n == 2) {
            return 1 + 1;
        }
        return CountCoin(n - 1) + CountCoin(n - 3);
    }
    
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        Integer n = sc.nextInt();
        System.out.println(CountCoin(n));
    }
}

Question 4 :

A physical education teacher asks students to assemble in a straight line for the morning assembly. In spite of repeated instructions, the students do not obey the teacher.
Given an array of N number of arguments in which each element represents the height of the student in that position. The task here is to find the number of students, only for students numbered 1 to N -1(a[1] to a[N-1]), whose height is less than the height of their adjacent students.

Example 1:

Input:

5-Value of N
(35,15,45,25,55) –a[] . Elements a[0] to a[n-1].
where each input element is separated by a new line

Output:
2- Number of elements whose adjacent elements are greater

Output 2 Nuhiber of elements whose

elegs are greater

Explanation:

From the input array given above

a[0]=35
a[1]=15
a[2)=45
a[3)=25
a[4]=55

The elements whose adjacent values are greater are 15 and 25 as

a[0]>a[1]15<45 a[2]>a[3]25<55

Hence, the output is 2.

Solution


//Solution by Technoname.com


import java.util.Scanner;
class Technoname 
{
	public static void main(String[] args)
	{
        Scanner sc = new Scanner(System.in);
        Integer n = sc.nextInt();
        Integer[] arr = new Integer[n];
        for (int i = 0; i < n; i++)
        {
            arr[i] = sc.nextInt();
        }
        int count=0;
        for (int i = 0; i < n-2; i++) {
            if (arr[i] > arr[i+1] && arr[i+2] > arr[i+1])
            {
                count++;
            }
        }
        System.out.println(count);
    }
}

Question number 1 and 2 was asked in morning slot 11 AM and Question number 3 and 4 were asked in evening slot of 4 pm.

Also, check some other coding questions that were asked in the previous DCA (Digital capability Assessment) from here

Please check most asked programming questions of strings with examples by clicking here, after that you might get a deep knowledge about string operations, in short, it will be helpful in clearing the interview

Thanks for reading this article so far. If you like this article, then please share it with your friends and colleagues. If you have any questions or feedback, then please drop a note.

You can also follow us on Twitter for daily updates.

8 responses to “TCS Digital Coding Questions Solved : 27 Sept 2021”

  1. globin says:

    hi , can you help in todays dca. telegram : @globinsey

  2. Amir says:

    Fantastic ways of solving problem. But can you please explain the coin problem of how adding count(n-1) and count(n-3) works?

  3. RAhul says:

    i am also stuck at this. if you know please tell?

  4. Avirup Ghosh says:

    Actually if you see:
    For 1 rs – no of way is 1
    For 2 rs – no of way is 2
    For 3 rs – no of way is 3
    For 4 rs – no of way is 4
    For 5rs – no of way is 6
    If you now look closely you can break like this: no of way(5 rs) = no of way(4 rs) + no of way (2 rs)

    it can true for 6 also , 7 also so on

  5. Yogita says:

    UNO or NOT UNO

    num=input()
    def UNO(num):
    if len(num)==1:
    # print(num)
    return num
    else:
    num=list(map(int,list(num)))
    s=sum(num)
    result=UNO(str(s))
    return result
    uno=UNO(num)
    if uno==’1′:
    print(“UNO”)
    else:
    print(“NOT UNO”)

  6. Yogita Sahu says:

    UNO or NOT UNO

    num=input()
    def UNO(num):
    if len(num)==1:
    # print(num)
    return num
    else:
    num=list(map(int,list(num)))
    s=sum(num)
    result=UNO(str(s))
    return result
    uno=UNO(num)
    if uno==’1′:
    print(“UNO”)
    else:
    print(“NOT UNO”)

  7. Ambika Sadh says:

    Another way to solve UNO or NOT UNO problem:

    #include
    using namespace std;

    int len(int n){
    int c=0;
    while(n!=0){
    n = n/10;
    c +=1;
    }
    return c;
    }

    int sum1(int temp){

    int sum=0,rem;
    while(temp!=0){
    rem = temp%10;
    sum += rem;
    temp = temp/10;
    }
    if(len(sum)==1){
    return sum;

    }
    else{
    sum1(sum);
    }
    }
    int main(){

    int n;
    cin>>n;

    int temp =n;
    // cout<<"len:"<<len(n)<<endl;
    if (len(n)==1){
    if (n==1){
    cout<<"UNO"<<endl;
    }
    else{
    cout<<"NOT UNO"<<endl;
    }
    }
    else{

    if(sum1(n)==1){
    cout<<"UNO"<<endl;
    }
    else{
    cout<<"NOT UNO"<<endl;
    }
    }

    }

Leave a Reply

Your email address will not be published. Required fields are marked *