TCS Elevate Wings1 DCA Coding Questions & Solutions 2024 | Python, Java, MCQs & Exam Tips

TCS Elevate Wings1 DCA Coding Questions & Solutions 2024 | Python, Java, MCQs & Exam Tips

Sunday, October 27, 2024
~ 6 min read
TCS Elevate Wings1 DCA Coding Questions With Solutions 2024: This guide offers essential resources for the TCS Elevate Wings1 DCA coding exam. TCS conducts this coding test as part of its hiring process annually, recruiting for various roles. If you're preparing for the TCS Elevate Wings1 DCA coding round, this article provides the practice questions, solutions, and tips required to excel. Candidates who pass the coding test will advance to the next stages of the hiring process. The coding questions can be solved in multiple programming languages such as Java, C, C++, and Python. Make sure to go through these questions and solutions before your test to improve your chances. This article also includes additional details on topics like cut-off marks, salary packages, increments, and appraisals.

Problem 1: Parallel Columbus

Problem Statement
A Nobel Prize-winning physicist creates a grid-based race with multiple versions of Christopher Columbus from parallel universes. Columbus explores the grid starting from (1,1). However, when Columbus encounters people at cell (x, y), he believes it is India and halts exploration.

Given grid dimensions and coordinates of the "American" cell, determine how many different Columbus(s) will encounter people at (n, m) for the first time.

Function Description:

Complete the `markgame` function with the following parameters:
- n: Number of rows in the grid.
- m: Number of columns in the grid.
- x: Row coordinate of the American cell.
- y: Column coordinate of the American cell.

Constraints:

  • 1 ≤ n, m ≤ 100
  • 1 ≤ x ≤ n
  • 1 ≤ y ≤ m

Sample Case:

Input:

2
2
2
1

Output:

1

Explanation:
The only path is:
(1,1) -> (2,1) -> (2,2)


C++ Solution:

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

unordered_map<int, long long int> f;

long long int Fact(int n) {
    if (f[n]) return f[n];
    return f[n] = n * Fact(n - 1);
}

int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    n -= 1; m -= 1; x -= 1; y -= 1;
    f[0] = f[1] = 1;

    int totalPaths = (Fact(m + n) / (Fact(m) * Fact(n)));
    int blockedPaths = (Fact(x + y) / (Fact(x) * Fact(y))) * 
                       (Fact(m - x + n - y) / (Fact(m - x) * Fact(n - y)));

    cout << totalPaths - blockedPaths;
}

Python Solution:

import math

n = int(input()) - 1
m = int(input()) - 1
x = int(input()) - 1
y = int(input()) - 1

total_paths = math.factorial(n + m) // (math.factorial(n) * math.factorial(m))
blocked_paths = (math.factorial(x + y) // (math.factorial(x) * math.factorial(y))) * \
                (math.factorial(n - x + m - y) // (math.factorial(n - x) * math.factorial(m - y)))

print(total_paths - blocked_paths)

Problem 2: Amusement Park Discount

Problem Statement
Students visiting an amusement park can earn discounts based on their coding ability. Given a string representing ticket costs and a number (K) (the number of tickets to remove), find the smallest possible ticket cost after removal.


Constraints:

  • 1 ≤ number of tickets ≤ 10^5
  • 1 ≤ K ≤ number of tickets

Sample Input:

203
3

Sample Output:

0

C++ Solution:

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

int smallestNumber(string num, int k) {
    if (num.length() <= k) return 0;

    unordered_map<char, int> pos;
    for (int i = 0; i < num.length(); i++) pos[num[i]] = i;

    string temp = num;
    sort(num.begin(), num.end());

    string ans = num.substr(0, num.length() - k);
    vector<int> indices;

    for (char ch : ans) indices.push_back(pos[ch]);
    sort(indices.begin(), indices.end());

    string result;
    for (int idx : indices) result += temp[idx];

    return stoi(result);
}

int main() {
    string s;
    cin >> s;
    int k;
    cin >> k;

    cout << smallestNumber(s, k) % (int)(pow(10, 9) + 7);
}

Python Solution:

n = input()
k = int(input())
n_len = len(n)

if n_len <= k:
    print(0)
else:
    result = ""
    i = 0
    while i < (n_len - 1) and k > 0:
        if int(n[i]) > int(n[i + 1]):
            k -= 1
            i += 1
        else:
            result += n[i]
            i += 1
    result += n[i:]
    print(int(result[:-k]) if k > 0 else int(result) % (10**9 + 7))

TCS Elevate Wings1 Text Sorting Problem

Given several lines of text, sort them by the number of occurrences of a specific word.


Example:

Input:

3
python
I love python
python is awesome
learning python is fun

Output:

learning python is fun
I love python
python is awesome

Python Solution:

n = int(input())
word = input().lower()
texts = [input().lower() for _ in range(n)]

texts.sort(key=lambda x: x.count(word))
print("\n".join(texts))

Prepare well with these coding questions and solutions to maximize your performance in the TCS Elevate Wings1 coding exam.

Post a comment

Comments

Join the conversation and share your thoughts! Leave the first comment.

Get your FREE PDF on "100 Ways to Try ChatGPT Today"

Generating link, please wait for: 60 seconds

Checkout all hot deals now 🔥

Search blogs

No blog posts found