Tata Elxsi Coding Questions

Tata Elxsi Coding Questions 2023

Tata Elxsi Coding Questions are frequently asked by TATA ELXSI Placement Paper in Written Assessment. It is an elimination round and the student is given a choice to choose any C/C++/JAVA/Python for coding purpose in which he/she is comfortable with.

There is a written assessment of 120 minutes which is necessary for a student to qualify for the further proceedings. Go through the page to know more details.

Tata Elxsi Question

About Tata Elxsi

One of the top companies in the world for design and technology services, Tata Elxsi works with clients in the automotive, broadcast, communications, healthcare, and transportation sectors.

Below are the key points that everyone should read to have a complete picture about Tata Elxsi Placement Exam, from registration to selection. The process includes two rounds:-

  1. Written Assessment
  2. Technical and HR Interview

Prime Course Trailer

Tata Elxsi Eligibility Criteria

Academic Qualifications :

  • Class 10th Standard : 60% or Above
  • Class 12th Standard : 60% or Above
  • College Graduation : 60% or Above 6.5 CGPA

Eligible Passing Year:

  • 2023

College Qualification Required:

  • B.E.
  • B.Tech.

Eligible Branches:

  • CS/IT/Circuital Branches

Other Important Criteria:

  • There should be No Backlogs at the time of Selection Process.
  • The education gap should be of maximum 1 years,if any, is allowed between 10th and graduation.
  • Should be from a Full-time Degree course recognized by the Central/State Government of India.
  • The candidates must not have any pending attendance requirement with the college.
  • Should be Indian Citizen or should carry a PIO or OCI card, in case holding a passport of any other country.

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Tata Elxsi Written Assessment

Tata ElxsiNumber of QuestionsTimeDiifficulty
Verbal Ability3048 minsMedium
Reasoning Ability3030 minsMedium
Coding Round 11UntimedHard
Coding Round 21UntimedHard

Analysis of Tata Elxsi Written Exam

*Untimed means these sections are without any specific time limit. You can answer these within the total assessment time limit, i.e., Total Time of Untimed Sections = Total Assessment Time Limit – Total Time of Timed Sections. Hence,

  • Total Time of Untimed Sections = 120 – 78 = 42 minutes

Tata Elxsi Coding Questions

Question 1 : Move Hash to Front

Problem Statement :

You have write a function that accepts, a string which length is “len”, the string has some “#”, in it you have to move all the hashes to the front of the string and return the whole string back and print it.

char* moveHash(char str[],int n);

Example :
Sample Test Case
Input :
Move#Hash#to#Front
Output :
###MoveHashtoFront

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

using namespace std;
string moveHash(string s) {
    string ans = "";
    for (auto i: s)
        if (i == '#') ans = '#' + ans;
        else ans += i;
    return ans;
}

int main() {
    string s;
    getline(cin, s);
    cout << moveHash(s);
}
Run
import java.util.*;
public class Main {
    public static void moveHash(String str, int n) {
        String str1 = new String("");
        String str2 = new String("");
        int i = 0;
        for (i = 0; i < n; i++) {
            if (str.charAt(i) == '#')
                str1 = str1 + str.charAt(i);
            else
                str2 = str2 + str.charAt(i);
        }
        String result = str1.concat(str2);
        System.out.println(result);
    }
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String a = sc.nextLine();
        int len = a.length();
        moveHash(a, len);
    }
}
Run
def moveHash(s):
    x = s.count("#")
    s = s.replace("#", "")
    return "#" * x + s
s = input()
print(moveHash(s))

Question 2 :Borrow Number

Problem Statement  :

You have two numbers number1 and number2, your job is to check the number of borrow operations needed for subtraction of number1 from number2. If the subtraction is not possible then return the string not possible.

Example :

754
658

Answer :
2

654
666

Answer :
Not possible

Run
#include &bits/stdc++.h>

using namespace std;

int main() {
    string s1, s2;
    int c = 0, f = 0;
    cin >> s1 >> s2;
    if (stoi(s1) < stoi(s2)) {
        cout << "Impossible";
    }
    reverse(s1.begin(), s1.end());
    reverse(s2.begin(), s2.end());
    for (int i = 0; i < s1.length(); i++)
        if (s1[i] < s2[i]) {
            f = 1;
            c++;
        }
    else if (s1[i] == s2[i]) {
        if (f == 1) {
            c++;
        }
        f = 0;
    } else f = 0;
    cout << c;
}
Run
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int number1 = sc.nextInt();
        int number2 = sc.nextInt();
        int count = 0;
        if (number1 < number2) {
            System.out.println("Not possible");
        } else {
            boolean flag = false;
            while (number1 != 0 && number2 != 0) {
                int temp1 = 0;
                int temp2 = number2 % 10;
                if (flag)
                    temp1 = number1 % 10 - 1;
                else
                    temp1 = number1 % 10;
                if (temp1 < temp2) {
                    count++;
                    flag = true;
                } else
                    flag = false;
                number1 = number1 / 10;
                number2 = number2 / 10;
            }
            System.out.println(count);
        }

    }

}
Run
number1 = int(input())
number2 = int(input())
count = 0
if number1 < number2:
    print("Not possible")
else:
    flag = 0
    while number1 != 0 and number2 != 0:
        temp1 = 0
        temp2 = number2 % 10
        if flag:
            temp1 = number1 % 10 - 1
        else:
            temp1 = number1 % 10
        if temp1 < temp2:
            count += 1
            flag = 1
        else:
            flag = 0
        number1 = number1 // 10
        number2 = number2 // 10
    print(count)

Question 3 : Capitalize/Decapitalize

Problem Statement  :

You’re given a function that accepts the following, a string1, its length and a character c. Your job is to replace all the occurrences of character c in string1 and capitalize it or decapitalize it based on the character c.

Input :
hello world
l
Output :
heLLo worLd

Input :
prepinsta
p
Output :
PrePinsta

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

using namespace std;

int main() {
    string s;
    getline(cin, s);
    char k;
    cin >> k;
    for (auto i: s)
        if (i == k) {
            if (i > 95) cout << char(i - 32);
            else cout << char(i + 32);
        }
    else cout << i;
}
Run
import java.util.Scanner;
public class Main {
    public static void change(String str, char c, int len) {
        char[] ch = str.toCharArray();
        for (int i = 0; i < ch.length; i++) {
            if (c == ch[i]) {
                if (Character.isUpperCase(ch[i])) {
                    ch[i] = Character.toLowerCase(ch[i]);

                } else if (Character.isLowerCase(ch[i])) {
                    ch[i] = Character.toUpperCase(ch[i]);

                }
            }
        }
        System.out.print(new String(ch));
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        char c = sc.next().charAt(0);
        int len = str.length();
        change(str, c, len);
    }
}
Run
ss = input()
k = input()
if k.isupper():
    s = s.replace(k, chr(ord(k) + 32))
else:
    s = s.replace(k, chr(ord(k) - 32))
print(s)

Question 4 : Individual Character Count

Problem Statement  :

You’re given a string where multiple characters are repeated consecutively. You’re supposed to reduce the size of this string using mathematical logic given as in the example below :


Input :
aabbbbeeeeffggg

Output:
a2b4e4f2g3


Input :
abbccccc

Output:
ab2c5

Run
#include 

using namespace std;

int main() {
    string s;
    getline(cin, s);
    map < char, int > m;
    for (auto i: s) m[i]++;
    for (auto i: m) cout << i.first << i.second;
}
Run
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int i, j, k = 0, count = 0;
        String uni = new String("");
        for (i = 0; i < str.length(); i++) {
            count = 0;
            for (j = 0; j <= i; j++) {
                if (str.charAt(i) == str.charAt(j)) {
                    count++;
                }
            }
            if (count == 1) {
                uni = uni + str.charAt(i);
            }
        }
        for (i = 0; i < uni.length(); i++) {
            count = 0;
            for (j = 0; j < str.length(); j++) {
                if (uni.charAt(i) == str.charAt(j)) {
                    count++;
                }
            }
            if (count == 1) {
                System.out.printf("%c", uni.charAt(i));
            } else {
                System.out.printf("%c%d", uni.charAt(i), count);
            }
        }
    }
}
Run
s = input()
i = 1
c = 1
while i < len(s):
    if s[i] == s[i - 1]:
        c += 1
    else:
        print(s[i - 1], end="")
        print(c, end="")
        c = 1
    i += 1
print(s[i - 1], end="")
print(c)

Question 5 :Make It Palindrome

Problem Statement  :

You’re given a string, you’ve to print additional characters needed to make that string a palindrome.

A Palindrome is a sequence of characters that has the property of reading the same in either direction.

Input :
abede
Output :
ba


Sample Input :
abcfe

Sample output :
fcba

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

using namespace std;

bool Pal(string s) {
    string s1 = s;
    reverse(s1.begin(), s1.end());
    return s1 == s;
}

int main() {
    string s;
    getline(cin, s);
    int i;
    for (i = 0; i < s.length() - 1; i++)
        if (Pal(s.substr(i, s.length() - i))) break;
    s = s.substr(0, i);
    reverse(s.begin(), s.end());
    cout << s;
}
Run
import java.util.*;
public class Main {
  public static boolean isPalindrome(String str) {
    char arr[] = str.toCharArray();
    for (int i = 0, j = arr.length - 1; i < j; i++, j--)
      if (arr[i] != arr[j])
        return false;
    return true;
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    String res = "";
    for (int i = 0; i < str.length(); i++) {
      if (isPalindrome(str.substring(i, str.length()))) {
        res = str.substring(0, i);
        break;
      }
    }
    System.out.println(new StringBuilder(res).reverse());
  }
}
Run
def ispalindrome(s):
    return s == s[::-1]

def solve(s):
    if ispalindrome(s):
        return None
    for i in range(len(s)):
        x = s[:i][::-1]
        if ispalindrome(s + x):
            return x

s = input()
print(solve(s))

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription