TCS CodeVita Previous Year Solution 2022

TCS CodeVita Previous Year Questions 2022

TCS CodeVita is a contest for engineering and science students to experience the joy of coding and to sharpen their programming skills through real-life computing practices. The contest also aims at identifying the talent, besides providing the student community, with an opportunity to earn peer recognition.

TCS CodeVita gives a set of sample questions for letting the students anticipate the difficulty level and pattern of the competition before the exam. TCS CodeVita Season 10 is conducted in three rounds.

  • Round 1 -: Pre-Qualifier.
  • Round 2 -: Qualifier
  • Round 3 -: Grand Finale.

If you solve all 6 TCS Codevita Coding questions then, the winners of the competition get a recruitment offer from TCS and whopping prize money of 20,000 US$ and many other benefits.

Constellation Problem Solution

Problem Description

Three characters { #, *, . } represents a constellation of stars and galaxies in space. Each galaxy is demarcated by # characters. There can be one or many stars in a given galaxy. Stars can only be in the shape of vowels { A, E, I, O, U }. A collection of * in the shape of the vowels is a star. A star is contained in a 3×3 block. Stars cannot be overlapping. The dot(.) character denotes empty space.

Given 3xN matrix comprising of { #, *, . } character, find the galaxy and stars within them.

Note: Please pay attention to how vowel A is denoted in a 3×3 block in the examples section below.

Constraints

  • 3 <= N <= 10^5

Input

  • Input consists of a single integer N denoting the number of columns.

Output

  • The output contains vowels (stars) in order of their occurrence within the given galaxy. The galaxy itself is represented by the # character.

Example 1

Input

18
* . * # * * * # * * * # * * * . * .
* . * # * . * # . * . # * * * * * *
* * * # * * * # * * * # * * * * . *

Output

U#O#I#EA

Explanation

As it can be seen that the stars make the image of the alphabets U, O, I, E, and A respectively.

Example 2

Input

12
* . * # . * * * # . * .
* . * # . . * . # * * *
* * * # . * * * # * . *

Output

U#I#A

Explanation

As it can be seen that the stars make the image of the alphabet U, I, and A.

Possible solution:

Input:

12
* . * # . * * * # . * .
* . * # . . * . # * * *
* * * # . * * * # * . *

Solution of Constellation Problem

#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;cin>>n;
    char co[3][n];
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<n;j++)
        cin>>co[i][j];
    }
    for(int i=0;i<n-2;i++)
    {
        if(co[0][i]=='#') {cout<<"#";continue;}
        if(co[0][i]=='.' && co[0][i+1]=='*' && co[0][i+2]=='.')
        {
            if(co[1][i]=='*' && co[1][i+1]=='*' && co[1][i+2]=='*')
            if(co[2][i]=='*' and co[2][i+1]=='.' and co[2][i+2]=='*')
            cout<<"A";i+=2;continue;
        }
        if(co[0][i]=='*' and co[0][i+1]=='*' and co[0][i+2]=='*')
        {
            if (co[1][i]=='*' and co[1][i+1]=='*' and co[1][i+2]=='*')
            {
                if (co[2][i]=='*' and co[2][i+1]=='*' and co[2][i+2]=='*')
                {cout<<"E";i+=2;continue;}
            }
            else if(co[1][i]=='.' and co[1][i+1]=='*' and co[1][i+2]=='.')
            {
                 if (co[2][i]=='*' and co[2][i+1]=='*' and co[2][i+2]=='*')
                 {cout<<"I";i+=2;continue;}
            }
            else if(co[1][i]=='*' and co[1][i+1]=='.' and co[1][i+2]=='*')
            {
                if(co[2][i]=='*' and co[2][i+1]=='*' and co[2][i+2]=='*')
                {cout<<"O";i+=2;continue;}
            }
        }
        if(co[0][i]=='*' and co[0][i+1]=='.' and co[0][i+2]=='*')
        if(co[1][i]=='*' and co[1][i+1]=='.' and co[1][i+2]=='*')
        if(co[2][i]=='*' and co[2][i+1]=='*' and co[2][i+2]=='*')
        {cout<<"U";i+=2;continue;}
    }
}
n=int(input())
co=[]
for i in range(3):co.append(list(input().split()))
i=0
while i<n-2:
    if co[0][i]=='#':
        print("#",end="")
        i+=1
        continue
    if co[0][i]=='.' and co[0][i+1]=='*' and co[0][i+2]=='.':
        if co[1][i]=='*' and co[1][i+1]=='*' and co[1][i+2]=='*':
            if co[2][i]=='*' and co[2][i+1]=='.' and co[2][i+2]=='*':
                print('A',end="")
    if co[0][i]=='*' and co[0][i+1]=='*' and co[0][i+2]=='*':
        if co[1][i]=='*' and co[1][i+1]=='*' and co[1][i+2]=='*':
            if co[2][i]=='*' and co[2][i+1]=='*' and co[2][i+2]=='*':
                print('E',end="")
                i+=3
                continue
        elif co[1][i]=='.' and co[1][i+1]=='*' and co[1][i+2]=='.':
            if co[2][i]=='*' and co[2][i+1]=='*' and co[2][i+2]=='*':
                print('I',end="")
                i+=3
                continue
        elif co[1][i]=='*' and co[1][i+1]=='.' and co[1][i+2]=='*':
            if co[2][i]=='*' and co[2][i+1]=='*' and co[2][i+2]=='*':
                print('O',end="")
                i+=3
                continue
    if co[0][i]=='*' and co[0][i+1]=='.' and co[0][i+2]=='*':
        if co[1][i]=='*' and co[1][i+1]=='.' and co[1][i+2]=='*':
            if co[2][i]=='*' and co[2][i+1]=='*' and co[2][i+2]=='*':
                print('U',end="")
                i+=3
                continue
    i+=1

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saransh Saurav

Saransh Saurav

Articles: 68

Leave a Reply

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