TCS DCA 2021 Questions Solved: 28 September 2021

TCS DCA Coding Questions

This blog contains TCS DCA (Digital Capability Assessment) Questions that were asked on 28th September 2021 morning slot 11 AM.

Evening slot questions of TCS Digital capability assessment can be accessed from here.

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.

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

Question 1

A man invests a certain amount on monthly basis in a bank. He withdraws that money once in 4 years which is a leap year, to make a big scale purchase .He starts next investment exactly 183 days after the purchase .

Initially, he makes a note of his purchase date
Given the date(dd) and month(mm) of his purchase. The task here is to help him find the date and month to start his investment.

His next investment date is calculated from the next day of his purchase.
Display the date as on 183rd day.

This question was asked in 28th September 2021 Morning Slot at 11 am

Example 1:

Input:

15–Value of dd
January-Value of mm

Output:

16 July- Date 183 days after his purchase

Constraints:

D<dd<=12
mm – {January to December}

Inputs

First input-Accept value for dd (positive integer number).

Second Input-Accept value for mm (month)


The output format for testing:
The output should be a positive integer number followed by the name of the month.

Solution in Python

# Solution by Technoname.com

def getDate(d, m):
 days = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
 month = ['January', 'February',
   'March', 'April',
   'May', 'June',
   'July', 'August',
   'September', 'October',
   'November', 'December']
 cnt = 183
 cur_month = month.index(m)
 cur_date = d
 while(1):
  while(cnt > 0 and cur_date <= days[cur_month]):
   cnt -= 1
   cur_date += 1
  if(cnt == 0):
   break
  cur_month = (cur_month + 1) % 12
  cur_date = 1
 print(cur_date, month[cur_month])
D = int(input())
M = input()
getDate(D, M)

Solution in Java

//Solution by Technoname.com

import java.util.Scanner;

class Technoname
{
	public static void getDate(int d, String m)
	{
		 int[] days = { 31, 29, 31, 30, 31, 30,
		    31, 31, 30, 31, 30, 31 };
		 String[] month = { "January", "February", "March",
		     "April", "May", "June", "July",
		     "August", "September", "October",
		     "November", "December" };
		 int count = 183;
		 int current_month = 0;
		 for(int i = 0; i < 12; i++)
		  if (m == month[i])
		   current_month = i;
		 int current_date = d;
		
		 while (true)
		 {
			  while (count > 0 && current_date <= days[current_month])
			  {
			   count -= 1;
			   current_date += 1;
			  }
			  if (count == 0)
			  break;
			  current_month = (current_month + 1) % 12;
			  current_date = 1;
		 }
		 System.out.println(current_date + " " +month[current_month]);
	}
	public static void main(String args[])
	{
		 int D;
		 String M;
		 Scanner sc=new Scanner(System.in);
		 D=sc.nextInt();
		 M=sc.next();
		 getDate(D, M);
	}
}

Solution in C++

//Solution by Technoname.com and contributed by akash99@gmail.com

 #include <iostream>
using namespace std;

void getDate(int d, string m)
{
int days[] = {31, 29, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31};
string month[] = {“January”, “February”, “March”,
“April”, “May”, “June”, “July”,
“August”, “September”, “October”,
“November”, “December”};
int count = 183;
int current_month = 0;
for (int i = 0; i 0 && current_date <= days[current_month])
{
count -= 1;
current_date += 1;
}
if (count == 0)
break;
current_month = (current_month + 1) % 12;
current_date = 1;
}
cout << current_date << " " <> D;
cin >> M;
getDate(D, M);

return 0;
}

Question 2 :

There are ‘N’ number of companies participating in the drive. The commencement timings of the interviews of ‘N’ companies is given as start[] array elements and their respective end timings are given as end[] array elements. The task here is to find the maximum number of interviews a single candidate can attend keeping the following points in mind:
All the interview timings are in ‘p.m’.
• The candidate cannot attend an interview if its timings overlap with the timings of another company’s interview. Say, an interview starts at 1 p.m. and ends at 4 p.m., he cannot attend the interview of another company between 1 p.m. to 4 p.m.
Only one candidate can be scheduled in the given time slot
Assume, the input for end time(end[]) is always sorted in ascending order.

Example

Input

66- Value of N
(2,4,1,6,9,6)-start[], Elements start[0] to start[N-1],
where each input element is separated by a new line

(3,5,7,8,10,10)-end[], Elements end[0] to end[N-1], where each input element is separated by a new line


Output
4

Solution in Java

//Solution by Technoname.com

import java.util.Scanner;

class TechnoName
{
	public static void main(String args[]) 
	{
	    Scanner Sc=new Scanner(System.in);
	    int size=Sc.nextInt();
	    int[] starttime=new int[size];
	    int[] endtime=new int[size];
	    for(int i=0;i<size;i++) 
	    {
	      starttime[i]=Sc.nextInt();
	    }
	    for(int j=0;j<size;j++) 
	    {
	      endtime[j]=Sc.nextInt();
	    }
	    int count=1;
	    int result=endtime[0];
	    for(int k=0;k<size-1;k++)
	    {
	      
	      if(result<=starttime[k+1])
	      {
	    	  result=endtime[k+1];
	        count++;
	      }
	    }
	    System.out.println(count);
	  }
	}

The above question is solved in Java, if you know the solution of the above code in any other language then please let us know in the comment section.

Question numbers 1 and 2 were asked in morning slot 11 AM, Evening slot questions are 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.

47 responses to “TCS DCA 2021 Questions Solved: 28 September 2021”

  1. Akash says:

    At what time you have updated these coding questions here bro??

  2. Abhi says:

    Is there any Telegram group?

  3. Akash says:

    Please upload the answers in C++ too if you can.
    Thanks,

  4. Akash says:

    1. First program in C++:

    #include
    using namespace std;

    void getDate(int d, string m)
    {
    int days[] = {31, 29, 31, 30, 31, 30,
    31, 31, 30, 31, 30, 31};
    string month[] = {“January”, “February”, “March”,
    “April”, “May”, “June”, “July”,
    “August”, “September”, “October”,
    “November”, “December”};
    int count = 183;
    int current_month = 0;
    for (int i = 0; i 0 && current_date <= days[current_month])
    {
    count -= 1;
    current_date += 1;
    }
    if (count == 0)
    break;
    current_month = (current_month + 1) % 12;
    current_date = 1;
    }
    cout << current_date << " " <> D;
    cin >> M;
    getDate(D, M);

    return 0;
    }

  5. Akash says:

    #include

  6. Bishu says:

    def function(day,month):
    #d = list()
    m = [“january”,”february”,”march”,”april”,”may”,”june”,”july”,”august”,”september”,”october”,”november”,”december”]
    d = [31,29,31,30,31,30,31,31,30,31,30,31]
    s = month.lower()
    j = -1
    for i in range(12):
    if m[i] == s:
    j = i
    break
    v = 183 + day
    j = j + 6
    if j > 11:
    j = j%12
    day = day + 1
    if day > d[j]:
    day = day % d[j]
    j = j+ 1
    res= str(day) + ” “+ str(m[j])
    print(res)

  7. Anonymous says:

    First program ans is wrong. If you give 31 December as input it will give 31 June as answer which is wrong

  8. Anon says:

    @Akshat Please update for DCA Sept 28 2021 : 4PM Slot also.

  9. rtxverma123 says:

    #Another approach, Python3

    a = int(input())
    b = input()
    month = [‘January’, ‘February’,
    ‘March’, ‘April’,
    ‘May’, ‘June’,
    ‘July’, ‘August’,
    ‘September’, ‘October’,
    ‘November’, ‘December’]
    c = 183
    month_ans = 0
    day = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    for i in range(0,len(month)-1):
    if ((i % 2) == 0) and (c>=31):
    c = c-31
    month_ans +=1
    elif ((i % 2) != 0) and (c>=30):
    c = c – 30
    month_ans +=1
    elif (month[i] == ‘February’) and (c>=29):
    c = c -29
    month_ans +=1
    p = c + 1
    x = 0
    for i in range(0,len(month)):
    if b in month:
    x = month.index(b)

    months = x + month_ans
    if months >12:
    months_1 = months – 12
    ans1 = month[months_1]
    else:
    ans1 = month[months]
    ans2 = a + p
    print(ans2,ans1)

  10. Raksha Pawar says:

    Second Program in Python:

    companies = int(input())
    start_times = []
    end_times = []

    for i in range(companies):
    start_times.append(int(input()))

    for j in range(companies):
    end_times.append(int(input()))

    count = 1
    res = end_times[0]
    for i in range(companies-1):
    if res <= start_times[i+1]:
    res = end_times[i+1]
    count += 1

    print(count)

  11. rehan says:

    If This is sept 28 11Am ques then how you are replying to Akash at sept 28 10:34 Am

    • Akshat Jain says:

      Brother, there is a time glitch in our website, will try to fix this soon
      And this blog is published after the exam, also you can verify these questions with anyone who gave the exam on 11 am
      Sorry for the inconvenience

  12. salman says:

    First Program in JAVA

    import java.util.Scanner;
    public class HelloWorld{

    public static void main(String []args){
    int[] days = { 31, 29, 31, 30, 31, 30,
    31, 31, 30, 31, 30, 31 };
    String[] month = { “January”, “February”, “March”,
    “April”, “May”, “June”, “July”,
    “August”, “September”, “October”,
    “November”, “December” };
    int D;
    String M;
    Scanner sc=new Scanner(System.in);
    D=sc.nextInt();
    M=sc.next();
    int td=0;

    for(int i=0;i366){
    td-=366;

    for(int i=0;itd){
    nd-=days[i];
    nm=i;
    nnd=td-nd;
    System.out.println(nnd+” “+month[nm]);
    break;

    }
    }
    }
    else{
    for(int i=0;itd){
    nd-=days[i];
    nm=i;
    nnd=td-nd;
    System.out.println(nnd+” “+month[nm]);
    break;

    }
    }
    }
    }
    }

  13. Rahul Sharma says:

    In the second question there was a condition that the candidate can choose to start from any company he/she wants. This piece of code will only work if the candidate starts from Company A i.e the first element in the array. All test cases will not pass.

  14. Sohail Shaik says:

    Hello Akash,
    Can you please upload 1st question in C

  15. kalyan says:

    2nd program

    n = int(input())
    s = []
    e = []
    rl = []
    t = []
    f = 1
    c = 1
    for i in range(n):
    s.append(int(input()))
    for i in range(n):
    e.append(int(input()))
    for i in range(s[0], e[0]+1):
    rl.append(i)

    for i in range(1, n):
    for j in range(s[i], e[i]+1):
    t.append(j)
    for x in t:
    if x in rl:
    f = 0
    break
    if f:
    rl = rl + t
    c += 1
    t = []
    f = 1
    print(c)

  16. Ravi Meher says:

    1st question in c++:

    #include
    using namespace std;

    int main()
    {
    int d;
    string m;
    cin>>d>>m;
    int days[]={31,29,31,30,31,30,31,31,30,31,30,31};
    string months[]={“January”,”February”,”March”,”April”,”May”,”June”,”July”
    ,”August”,”September”,”October”,”November”,”December”};
    int rd,cm;
    string rm;
    for(int i=0;i<12;i++)
    {
    if(m==months[i])
    { cm=i; break;}
    }
    rm=months[cm];
    rd = days[cm]-d;

    while(rd<182 && cm<12)
    {
    rd+=days[cm];
    cm++;
    }
    if(rd == 182)
    rd = days[cm];
    else
    rd = rd-182;

    cout<<rd<<" "<<months[cm];
    return 0;
    }

    2ns Question in C++:

    #include
    using namespace std;

    int main()
    {
    int n;
    cin>>n;
    int start[n];
    for(int i=0;i>start[i];
    int end[n];
    for(int i=0;i>end[i];
    int maxslots = INT_MIN;
    int currslots = 1;
    int s,e;
    for(int i=0;i<n;i++)
    {
    s=start[i];
    e=end[i];
    currslots = 1;
    for(int j=i+1;je)
    {
    currslots++;
    s=start[j];
    e=end[j];
    maxslots = max(currslots,maxslots);
    }
    }
    }
    cout<<maxslots<<endl;
    return 0;
    }

  17. kcoder says:

    dd=int(input())
    h=0
    mm=int(input())
    mm=str(mm)
    mm=mm.lstrip(‘0’)
    mm=int(mm)-1
    l=[31,29,31,30,31,30,31,31,30,31,30,31]
    k=183
    k=k-(l[mm]-dd)
    h+=1
    if mm==11:
    mm=1
    else:
    mm+=1
    while(k>0):
    k=k-l[mm]
    h+=1
    if mm<=10:
    if k<l[mm+1]:
    break
    elif mm==11 and k<l[1]:
    break
    else:
    pass
    if mm==11:
    mm=1
    else:
    mm+=1
    if mm==11:
    mm=1
    else:
    mm+=1
    print(k,mm)

  18. Ankit Singh says:

    1st Answer C++

    #include
    using namespace std;

    int main(){
    int n;
    cin>>n;
    int a[n],b[n];

    for(int i=0;i>a[i];
    }
    for(int i=0;i>b[i];
    }
    //sort the arrays according to end time if not
    // given sorted in input
    for(int i=0;i<n-1;i++){
    for(int j=0;j<n-i;j++){
    if(b[j+1]<b[j]){
    int temp=a[j+1];
    a[j+1]=a[j];
    a[j]=temp;
    temp=b[j+1];
    b[j+1]=b[j];
    b[j]=temp;
    }
    }
    }
    }

    int count=1;
    int end=b[0];
    for(int i=1;i=end){
    count++;
    end=b[i];
    }
    }
    cout<<count<<endl;
    return 0;
    }

    2nd Answer C++

    #include
    using namespace std;

    int main(){
    int n;
    cin>>n;
    int a[n],b[n];

    for(int i=0;i>a[i];
    }
    for(int i=0;i>b[i];
    }
    //sort the arrays according to end time if not
    // given sorted in input
    for(int i=0;i<n-1;i++){
    for(int j=0;j<n-i;j++){
    if(b[j+1]<b[j]){
    int temp=a[j+1];
    a[j+1]=a[j];
    a[j]=temp;
    temp=b[j+1];
    b[j+1]=b[j];
    b[j]=temp;
    }
    }
    }
    }

    int count=1;
    int end=b[0];
    for(int i=1;i=end){
    count++;
    end=b[i];
    }
    }
    cout<<count<<endl;
    return 0;
    }

  19. Ankit Singh says:

    1st Answer C++

    #include
    using namespace std;

    struct months{
    int days;
    string name;

    };

    int main(){
    int day;
    string month;
    cin>>day>>month;
    months arr[12];
    arr[0].days=31;
    arr[0].name=”January”;
    arr[1].days=29;
    arr[1].name=”February”;
    arr[2].days=31;
    arr[2].name=”March”;
    arr[3].days=30;
    arr[3].name=”April”;
    arr[4].days=31;
    arr[4].name=”May”;
    arr[5].days=30;
    arr[5].name=”June”;
    arr[6].days=31;
    arr[6].name=”July”;
    arr[7].days=30;
    arr[7].name=”August”;
    arr[8].days=31;
    arr[8].name=”September”;
    arr[9].days=30;
    arr[9].name=”Octomber”;
    arr[10].days=31;
    arr[10].name=”November”;
    arr[11].days=31;
    arr[11].name=”December”;
    int i;
    for( i=0;i0){
    i=i%12;
    if(diff-arr[i].days>0){
    diff=diff-arr[i].days;
    i++;
    }
    else{
    cout<<diff<<" "<<arr[i].name<<endl;

    day=0;
    }
    }

    return 0;
    }

    2nd Answer C++

    #include
    using namespace std;

    int main(){
    int n;
    cin>>n;
    int a[n],b[n];

    for(int i=0;i>a[i];
    }
    for(int i=0;i>b[i];
    }
    //sort the arrays according to end time if not
    // given sorted in input
    for(int i=0;i<n-1;i++){
    for(int j=0;j<n-i;j++){
    if(b[j+1]<b[j]){
    int temp=a[j+1];
    a[j+1]=a[j];
    a[j]=temp;
    temp=b[j+1];
    b[j+1]=b[j];
    b[j]=temp;
    }
    }
    }
    }

    int count=1;
    int end=b[0];
    for(int i=1;i=end){
    count++;
    end=b[i];
    }
    }
    cout<<count<<endl;
    return 0;
    }

  20. Aski says:

    # python approch 2nd problem
    start = [2,4,1,6,9,6]
    end = [3,5,7,8,10,10]

    res = 1
    E = end[0]
    for i in range(1 , len(start)):
    if start[i] <= E :
    res+=1
    E=end[i]

    print(res)

  21. Unnati says:

    Second Question in Python3:
    n = int(input())
    start =[]
    end = []
    for i in range(0,n):
    st_element= int(input())
    start.append(st_element)

    for i in range(0,n):
    en_element= int(input())
    end.append(en_element)

    start.sort()
    end.sort()
    print(start,end)
    count = 0

    for j in range(0,n-1):
    for i in range(1,n):
    if end[j]<start[i]:
    count+=1
    break

    print(count)

  22. VIGNESH GOPINATH says:

    2nd PROGRAM:

    n=int(input())
    st=[]
    et=[]
    for i in range(n):
    s=int(input())
    e=int(input())
    st.append(s)
    et.append(e)
    print(st)
    print(et)
    c=1
    x=et[0]
    for i in range(n-1):
    if x<=st[i+1]:
    x=et[i+1]
    c=c+1
    print(c)

  23. Rakshith R says:

    first program in java
    public static String addDate(int day, String month) {
    String[] arrayOfMonths = {“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”};
    List months = List.of(arrayOfMonths);
    LocalDate date = LocalDate.parse(“2000-” + months.indexOf(month) + 1 + “-” + day);
    List collectedDates = Arrays.stream(date.plusDays(183).toString().split(“-“)).toList();
    return months.get(Integer.parseInt(collectedDates.get(1))-1) + “-” + collectedDates.get(2);
    }

  24. Khushboo says:

    Hii can someone share mcq questions or where to get mcqs for tcs dca

  25. Rahul Dhiman says:

    N = 6
    start = [2,4,1,6,9,6]
    end = [3,5,7,8,10,10]

    count = 0
    for i in range(len(start)-1):
    if end[i] > start[i]:
    count+=1
    if start[i+1] in range(start[i],end[i]):
    count -= 1
    print(count)

  26. Rahul Dhiman says:

    2nd ques in python:

    N = 6
    start = [2,4,1,6,9,6]
    end = [3,5,7,8,10,10]

    count = 0
    for i in range(len(start)-1):
    if end[i] > start[i]:
    count+=1
    if start[i+1] in range(start[i],end[i]):
    count -= 1
    print(count)

  27. Saumya Sharma says:

    Q2 C++ code

    #include

    using namespace std;

    int main()
    {
    int n,i,c=1;
    cin>>n;
    int s[n],e[n];
    for(i=0;i>s[i]>>e[i];
    }
    if(n==0)
    cout<<"0";
    else if(n==1)
    cout<<"1";
    else
    {
    int temp=e[0];
    for(i=1;i=temp)
    {
    c++;
    temp=e[i-1];
    }
    }
    cout<<c;
    }
    return 0;
    }

  28. Saumya Sharma says:

    bro is there something wrong on the website. My Code is modified on pasting here. Making it syntactically wrong

  29. Shivam says:

    package dca_practice;
    import java.time.Month;
    import java.util.*;
    public class previous_Year {

    public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int days=sc.nextInt();
    String month=sc.next();
    imp(days,month);

    }
    public static void imp(int days,String month)
    {
    int dm=Month.valueOf(month.toUpperCase()).getValue();
    int tdm=dm+6;
    if(tdm>12)
    {
    tdm=tdm-12;
    }
    days=days+1;
    if(days>30)
    {
    tdm=tdm+(int)Math.ceil(days/30);
    days=days-30;

    }
    System.out.print(days+” “);
    System.out.println(Month.of(tdm).name());

    }

    }

Leave a Reply

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