TCS Digital Capability Assessment Solutions: 28 Sept 2021

TCS Digital Coding Questions

This blog contains TCS DCA (Digital Capability Assessment) coding questions and answers that were asked on 28 September 2021 in Second Slot at 4 pm.

You can also find out TCS DCA coding solutions asked on 28 September 2021: First Slot at 11 am from here.

You can also check out TCS DCA questions that were asked on 27th September from here.

For complete preparation of the TCS Digital Capability Assessment, you can visit our other blogs from here which contain previously asked questions from the DCA and they will help you to clear the test.

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 :

A faulty program stores values from the username and password fields as a continuous sequence of characters. When trying to fetch either the username or password, the entire string is displayed Given the string str, the task here is to find and extract only the letters and special characters from the whole string stored.

Note:

The letters and special characters should be displayed separately.

The output should consist of all the letters, followed by all the special characters present in the input string.

Example 1 :

Input:
name@1234password — Value of str
Output: namepassword@–only letters and special characters

Explanation:
From the inputs given above string name@1234password, Extracting only letters and special characters

Constraints:
Str = {A-Z, a-z, 0-9. special characters}
The input format for testing:
The candidate has to write the code to accept 1 input • First Input – Accept value for str (String)
The output format for testing:
The output should be only letters and special characters from the input string (check the output in Example 1 )
• Additional messages in the output will cause the failure of test cases. 299101 2991016
Instructions:
The system does not allow any kind of hardcoded input value/values

Solution :

//Solution by technoname.com

import java.util.Scanner;

public class Technoname
{
    static String Result(String s)
    {
        String alphabets="",specialCharacter="";
        for(int i=0;i<s.length();i++)
        {
            if((s.charAt(i)>='A'&& s.charAt(i)<='Z') || (s.charAt(i)>='a'&& s.charAt(i)<='z'))
            {
            	alphabets+=s.charAt(i);
            }
            else if(!(s.charAt(i)>='0'&& s.charAt(i)<='9'))
            {
            	specialCharacter+=s.charAt(i);
            }
        }
        return alphabets+specialCharacter;
    }
 public static void main(String[] args) 
 {
  Scanner sc=new Scanner(System.in);
  String s=sc.nextLine();
  System.out.println(Result(s));
 }
}

Question 2 :

Kids up to the age of 7 are confused formation of letters and numbers, teacher uses the different methodologies to make the concepts of mathematics clear to the students. One of the methods the teacher uses to emphasis on the addition and recognition of numbers is that she muddles up the numbers randomly and then asks the students to find difference between adjacent digits. The task here to find given number is CORRECT or INCORRECT.

• A number is correct if the between the adjacent (right and left) digits is 1.

• The number can be a positive or a negative


Example :
7876— Value of N
Output: CORRECT

Explanation:
the inputs given above:
N = 7876

Difference between the digits
7-8=-1
8-7=1
7-6 = 1
6-7 = -1
The maximum difference between all adjacent digits is 1, hence output is CORRECT.

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int number;
    cin>>number;
    number=abs(number);

    int remainder1=number%10;
    number=number/10;
    while(number>0)
    {
        int remainder2=number%10;
        if(abs(remainder1-remainder2)==1)
        { remainder1=remainder2;
            number=number/10;
        }
        else
            break;
    }
    if(number>0)
        cout<<"INCORRECT";
    else
        cout<<"CORRECT";
    return 0;
}

Question number 1 and 2 was asked in evening slot 4 PM, morning slot questions are also available here

You can 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.

21 responses to “TCS Digital Capability Assessment Solutions: 28 Sept 2021”

  1. coder_45 says:

    def check_st(st):
    rs = ”.join(i for i in st if not i.isnumeric())
    return rs

    st = ‘Name@123password’#input()

    print(check_st(st))

  2. coder_45 says:

    Python 3:

    Answer for problem 2:

    def check_st(st):
    st = str(st)
    l = ”
    for i in range(1,len(st)-1):
    if (abs(int(st[i-1]) – int(st[i])) == 1) \
    and (abs(int(st[i+1])- int(st[i])) == 1) \
    and (abs(int(st[0])- int(st[-1])) == 1):
    l = ”.join(‘i’)
    if len(l)>=1:
    print(‘CORRECT’)
    else:
    print(‘WRONG’)

    st = 7876 # input()

    print(check_st(st))

  3. Raksha Pawar says:

    First Code in Python (Removing numbers while keeping alphabets and special characters as it is)

    string = input()
    s1 = string
    chars_to_remove = [“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “0”]
    for character in chars_to_remove:
    s1 = s1.replace(character,””)

    print(s1)

    • Akshat Jain says:

      Good efforts, but there is one more condition in question that the letters and special characters should be displayed separately.
      So first all the letters should be displayed and then characters.

  4. Raksha Pawar says:

    Second code in Python:

    num = int(input())
    abs_num = abs(num)

    digit_list = [int(a) for a in str(abs_num)]
    diff_list = []

    for i in range (1, len(digit_list)):
    diff_list.append(digit_list[i] – digit_list[i-1])

    count = 0
    print(diff_list)
    for j in diff_list:
    if abs(j) != 1:
    count += 1

    if count > 0:
    print(“INCORRECT”)
    else:
    print(“CORRECT”)

  5. Akshay says:

    @coder_45 and @Raksha , you found aptitude easy or tough?

  6. Ritesh Balaji Gatpalli says:

    This One is optimized and easy to understand .
    def KidsPlan(s):
    sub = []
    for i in range(len(s)-1):
    sub.append(int(s[i])-int(s[i+1]))
    if max(sub) == 1:
    print(‘Correct’)
    else:
    print(‘Not Correct’)
    string = str(input())
    KidsPlan(string)

  7. Ritesh Balaji Gatpalli says:

    Your is so much better

    def RemoveNumber(s):
    Alpha = []
    Special = []
    for i in s:
    if ord(i) in range(ord(‘a’),ord(‘z’)) or ord(i) in range(ord(‘a’),ord(‘z’)):
    Alpha.append(i)
    if ord(i) not in range(ord(‘0’),ord(‘9’)) and i not in Alpha:
    Special.append(i)
    print(”.join(Alpha+Special))
    string = str(input())
    RemoveNumber(string)

  8. yukta priya says:

    n =(7876)
    p = list(map(int, str(n)))
    print(p)
    count =0
    try:
    for i in range (0,len(p)):
    if abs(p[i] -p[i+1]) == 1:
    count+=1
    print(‘Correct’,count)
    except IndexError:
    for i in range (len(p)-1,len(p)):
    if abs(p[len(p)-1] -p[0]) == 1:
    count+=1
    print(‘Correct’,count)

  9. Akshay Choure says:

    2nd code :

    num1=input()
    lst1=[]
    for i in num1:

    for j in range(len(num1)-1):

    if abs(int(num1[j+1])-int(num1[j])) == 1:

    lst1.append(1)
    else:

    lst1.append(0)
    if all(lst1):

    print(“correct”)

    else:

    print(“incorrect”)

  10. Kannan says:

    Q1.
    s=str(input())
    s=list(s)

    lst=[‘0′,’1′,’2′,’3′,’4′,’5′,’6′,’7′,’8′,’9′]
    for i in lst:
    if i in s:
    s.remove(i)
    for i in s:
    if i==’@’ or i==’*’ or i==’&’:
    s.remove(i)
    s.append(i)
    for i in s:
    print(i, end=””)

  11. Hrudini says:

    solution of second question in C

    #include
    #include
    #include
    int main ()
    {
    int n,x,y,i;
    scanf(“%d”,&n);
    x=n%10;
    n=n/10;
    while(n!=0)
    {
    y=x%10;
    n=n/10;
    if(abs(x-y)==1)
    {
    n=n/10;
    }

    }
    if(n>0)
    {
    printf(“Incorrect”);
    }
    else
    {
    printf(“Correct”);
    }

    return 0;
    }

  12. Sundram Dubey says:

    Q1:-
    import java.util.*;
    class Solution {
    public static void main(String[] args) {
    String str = new Scanner(System.in).nextLine();
    String temp = “”,end = “”;
    for (int i = 0; i < str.length(); i++)
    if(Character.isLetter(str.charAt(i)))temp +=str.charAt(i);
    else if(!Character.isDigit(str.charAt(i))) end += str.charAt(i);
    System.out.println(temp+end);
    }
    }

  13. Syeda khurrath says:

    #first code
    str = input()
    listi = []

    for letter in str:
    if letter.isdigit() == False and letter.isalpha():
    listi.append(letter)

    for letter in str:
    if letter.isdigit() == False and letter.isalpha() == False:
    listi.append(letter)
    res = “”.join(listi)
    print(res)

Leave a Reply

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