0% found this document useful (0 votes)
15 views3 pages

TCS CodeVita Sample Questions and Solutions

Uploaded by

nikhil211411
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

TCS CodeVita Sample Questions and Solutions

Uploaded by

nikhil211411
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

TCS CodeVita Sample Questions and Solutions

This document contains a selection of sample questions typically found in the TCS CodeVita coding

competition. Each question

illustrates different problem-solving areas such as array manipulation, mathematical puzzles, and

dynamic positioning.

The solutions provided demonstrate common approaches to tackle these types of challenges in

competitive programming.

Topic: Array and String Manipulation


Question:

You are given an array of integers representing the power levels of team members. Split them into

two teams such that

the absolute difference between the sum of their power levels is minimized. Alternate the members

between the teams based

on the sorted order of their absolute power values.

Solution:

To solve this problem:

1. Sort the power levels by their absolute values.

2. Alternately assign them to two teams.

3. Calculate the absolute difference in total power between both teams.

Topic: Mathematical and Logical Puzzles


Question:
A team of superheroes each has a unique power level represented by an integer. Arrange them into

two teams such that

the difference between the total power of each team is minimized.

Solution:

Approach:

1. Sort power levels in descending order.

2. Alternately assign power levels to two teams to balance them out.

3. Compute and return the absolute difference between their total power levels.

Topic: Dynamic Positioning


Question:

Given an initial string of numbers, perform a series of directional operations (like left, right,

increment, and decrement)

based on an input command sequence.

Example:

Input: 123456, Commands: RLTDRRTRS2S1

Output: 244156

Solution:

Solution:

1. Parse the command string and apply each command sequentially.


2. Commands like 'R' (move right) or 'L' (move left) shift the active position, while 'U' and 'D'

increment or decrement

the digit at that position.

3. 'S' commands swap the active digit with a digit at a specified position.

4. Output the transformed string after all operations.

Topic: Basic Encryption/Decryption


Question:

Encrypt a string of numbers based on directional commands. Commands might include shifting left

or right, and incrementing

or decrementing specific digits based on rules.

Solution:

Encryption Solution:

1. Start at the beginning of the string and move through according to each directional command.

2. Implement conditional checks to handle boundaries and ensure that numbers remain within valid

ranges.

3. Transform the string accordingly and output the encrypted sequence.

You might also like