DXC Coding Questions and Answers

DXC Coding Questions and Answers

DXC Coding Questions for 2024

DXC has updated its pattern for its 2024 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: Automata Section now contains Coding Questions in placement pattern of 2024, and automata fix is not asked in DXC On-campus placement exam.

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.

Use Coupon Code “CT10” and get a flat 10% OFF on your Prime Subscription plus:

  • 1 month extra subscription on 3 & 6 months plans
  • 2 months extra subscription on 12 & 24 months plans
  • 3 months extra subscription on 36 & 48 months plan

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.

Use Coupon Code “CT15” and get a flat 15% OFF on your Prime Subscription plus:

  • 1 month extra subscription on 3 & 6 months plans
  • 2 months extra subscription on 12 & 24 months plans
  • 3 months extra subscription on 36 & 48 months plan

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.

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

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

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

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”

Question 7

A company wishes to bucketize their item IDs for better search operations. The bucket for the item ID is chosen on the basis of the maximum value of the digit in the item ID. Write an algorithm to find the bucket to which the item ID will be assigned.

Input:
The input consists of an integer itemID, representing the identity number of the item.
Output:
Print an integer representing the bucket to which the itemID will be assigned.

Example:
723894
Output: 4

Question 8

A retail company is planning a promotional sale where they will offer a discount on all items in their store. The discount will not be a standard percentage or fixed amount but will be calculated based on the price of each individual item. The company has decided to calculate the discount as the sum of all prime digits in the item’s price. Write an algorithm to find the amount of discount the company will offer.
Input:
The input consists of an integer priceItem, representing the price of the item.
Output:
Print an integer representing the amount of discount.

Example:
84302
Output: 5

Question 9

You’ve just been hired as a software engineer for a tech company. Your first task is to work on an array processing algorithm.
You are given an array of integers, which could be both positive or negative. The company wants the array to be sorted in a specific way for their processing algorithm.
They need the array to be rearranged so that all the even numbers come before all the odd numbers. However, the relative order of the even and odd numbers should not be changed. In other words, they want to preserve the relative ordering of numbers of the same parity.
You are required to write a program that takes an array of integers as input and returns the array sorted according to these rules.
Input:
The input will consist of a single line containing n space-separated integers a[i] (-10^9 ≤ a[i] ≤ 10^9), where n is the size of the array.
Output:
Your program should output a single line containing n space-separated integers, representing the sorted array.
Example:
8
3 2 5 8 1 6 9 4
Output:
2 8 6 4 3 5 1 9

Question 10

Ravi has given n number of elements which contains elements from 0 to n having 1 number is missing , his task is to return the missing number from the given elements

Constraints :
1<=n<= 10^3
0<= nums[i] <= 10^3

Input :
4
1 2 0 4

Output :
3

Prime Course Trailer

Related Banners

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

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