# DXC Coding Questions and Answers ## DXC Coding Questions for 2023

DXC has updated its pattern for its 2023 drive. There are some new sections added in their recruitment drive, which will be testing students on their problem solving and coding capabilities. DXC Coding Questions and Answers in which there will be 2 problem statements, which you have to code in your desired coding languages.

Note: Coding is not asked anymore.

## DXC Coding Questions

DXC has introduced this new section where they will be testing the students upon their logical thinking and problem solving techniques, there will be two problem statements, which may represent some day to day problem or some specific issue, for which you have to write a complete code in any of your preferred coding languages. Some of the languages that you can use to code are-:

• C
• C++
• Java
• Python

Rules for DXC Coding Round Questions Section:

• There are two question for 45 minutes.
• We must start our code from the scratch.
• The coding platform is divided into two, one for writing the code and other for output.
• The errors are clearly mentioned.
• Atleast one Partial and One Complete Output is required for clearing the round.

### DXC Coding Round details

Total number of Questions2 Question
Total Time Duration45 minutes
Type of TestNon- Adaptive
Negative MarkingNo

Below are some coding questions which will help you in preparing for DXC Coding Round.

## DXC Coding Questions and Answers

Question 1

Problem statement

In an auditorium, the lighting system of N bulbs is placed in a row. Due to some technical fault in the power supply, only some of the bulbs remain ON and the rest of them go OFF. Due to this flaw in the network, the bulbs which are OFF are unable to work. So till the technical team finds the actual cause of the fault, the technical head Akshay makes some temporary arrangements for the OFF bulbs at a minimum cost. Akshay decides to connect all the OFF bulbs to the nearby ON bulbs so that the length of the cable used to connect them is minimum. He calculates the distance of the systems from the first system.

Write an algorithm to help Akshay find the minimum length of the cable used to turn all the bulbs ON.

Input

• The first line of the input consists of an integral num,  representing the number of bulbs (N).
• The second line consists of N space-separated integers representing the initial state of each bulb, ON(1) or OFF(0)
• The last line consists of N space-separated integers representing the distance of the bulbs from the first bulb.

Output

• Print an integer representing the minimum length of the cable used to turn all the bulbs ON.

Example

• Input:
• 3
• 1 0 0
• 1 5 6
• Output:
• 5

Explanation:

• Length of the cable required to connect the 2nd bulb to the 1st bulb =4
• Length of the cable required to connect the 3rd bulb to the 2nd bulb =1
• The total length of the cable = 5(4+1)

So, the output is 5.

```n = int(input())
states = list(map(int, input().split()))
distances = list(map(int, input().split()))
distance = 0
for i in range(len(distances)-1):
distance = distance + distances[i+1] - distances[i]
print (distance)```

Question 2

Mayur is developing a game that has three levels in it. He wants to display the results after the successful completion of all the levels for this purpose he is using a function int giveResult(int s1, s2, s3), where s1, s2, and s3 are the score of every level. This function will return “Good” if the s1<s2, “Best” if s1>= s2 and s1<=s3 and “Can do better” if s1>s3. Can you help Mayur in developing that function

• Input:
• s1 : 10
• s2 : 12
• s3 : 15
• Output :
• Good
• Explanation :
• Since 10 is less than 12, hence “Good” is returned.
```#include  <stdio.h>
int main()
{
int s1, s2, s3;
printf ("s1 : ");
scanf ("%d", &s1);
printf("s2 : ");
scanf("%d",&s2);
printf("s3 : ");
scanf("%d",&s3);
if(s1<s2)
{
printf("Good");
}
if(s1>s3)
{
printf("Can do better");
}
if((s1>=s2)&&(s1<=s3))
{
printf("Best");
}
return 0;
}```

Question 3

Problem Statement:

There are 3 Horses with different speeds(in m/s) in a horse race. The length of the Racing track is given by m meters. You have to calculate the minimum time (in secs.) the fastest horse will win the race.

Input

• The first line of input consists of an integer – Distance, representing the length of the racing track.
• The second line of the input consists of 3 space-separated integers representing the  speeds of horses running in the race.

Output

• Print the minimum time required to complete the race.

Note:

• Consider all arithmetic operations as integer operations
• Computed values lie within the integer range.

Example

• Input:
• distance: 72
• Speed of horse1: 8
• Speed of horse2: 4
• Speed of horse3: 6

• Output:
• 9

Explanation :

Time is taken by three horses to finish the race are :

• Time of first horse = 72/8 = 9
• Time of second horse = 72/4 = 18
• Time of third horse = 72/6 = 12

The minimum time is 9 secs. Thus, the output is 9

Sample Input

• distance: 18
• Speed of horse1 : 3
• Speed of horse2: 9
• Speed of horse3: 6

• Sample Output
• 2
```distance = int(input())
spd1, spd2, spd3 = map(int, input().split())
print(distance//(max(spd1, spd2, spd3)))```

Question 4

Problem Statement

Chinese Government wants to build a secret message encryption algorithm to encrypt important messages before transmission. The algorithm will have a message along with two keys which will be required necessarily for encryption as well as decryption of the secret message. The formula to encrypt the code is given below:

• (((messagekey2 % 5)key1)%7000000001)

Write an algorithm to Encrypt the Code.

Input

• The input consists of three space-separated integers – Message, Key1, and Key2, representing the secret code, the first key value, and the second key-value, respectively.

Output

• Print an integer representing the code encrypted.

Constraints

• 1<= Message <= 109
• 0 <= Key1, Key2<= 109

Example

• Input
• 4
• 5
• 1

• Output
• 1024
```message = int(input())
key1 = int(input())
key2 = int(input())
print(pow((pow(message, key2)%5),key1)%7000000001)```
```#include  <stdio.h>
#include <math.h>
int main()
{
long long int mes, k1, k2, result1, result2, temp;
scanf("%lld %lld %lld",&s,&n,&m);
result1 = (pow(mes,k1));
result1 = result1 % 10;
result2 = pow(result1,k2);
result2 = result2 % 1000000007;
printf("%lld",result2);
return 0;
}```

Question 5

Problem Statement

A Monitor of the class wanted to take the attendance, so he circulated a blank page in the classroom asking students to write there student_Id. But some naughty students wrote their id multiple times to trouble the monitor. Monitor went to the teacher and reported the incident, the Teacher asked him to mark the absence of students whose id is repeated in the attendance sheet and give him the number of students with repeated id in the attendance sheet.

Input

• The input consists of a string representing the ids of students.

Output

• Print an integer representing the count of characters that are not repeated in the string.

Note: Student id is nothing but an alphabet from a-z.

Example:

• Input:
• ghygbvghyghnhjuhjumnj

• Output:
• 3
• Explanation:
• As there are only 3 students whose ids are not repeating, i.e, d f g v c x and the students with ids repeating are a and s
```attendance = input()
count = 0
for i in attendance:
if attendance.count(i) < 2 :
count+=1
print(count)```

Question 6

Problem Statement

You have to select an integer number “check”  from the range 1 to max and then you have to print the following output after checking that number.

• If the check is a multiple of both 2 and 7, print “PrepInsta”
• If the check is a multiple of 2(but not 7), print “Prep”
• If the check is a multiple of 7(but not 2), print “Insta”
• If i is not a multiple of 2 and 7, print “Prepster”
```#include  <stdio.h>
int main()
{
int max, check;
scanf(" %d",&max);
for(check=1; check<=max; check++)
{
if((check%2==0)&&(check%7==0))
{
printf("PrepInsta\n");
}
else if(check%2==0)
{
printf("Prep\n");
}
else if(check%7==0)
{
printf("Insta\n");
}
else
{
printf("Prepster\n");
}
}
return 0;
}```
```check = int(input())
if check % 2 == 0:
print("Prep",end="")
if check % 7 == 0 :
print("Insta")
elif check % 7 == 0 :
print("Insta")
else:
print("Prepster")```