EY Coding Questions and Answers

EY Coding Questions with Solutions

Here, in EY Coding Questions and Answers page you will get Sample EY Coding Questions with Solutions which will help you to prepare for EY Recruitment Process. Make sure that you go through the whole page and at last get FAQ’s related to EY (Ernst & Young) Recruitment Process to clear all your doubts.

EY Coding

Sample EY Coding Questions with Answers - Set 1

Question 1 : Coloured Zenga

Problem Statement :

Rahul is playing a game, wherein he has multiple coloured wooden blocks, stacked one above the other, his task is to remove all the wooden blocks from the stack, without letting it fall and in the minimum number of steps. He can remove one block of a colour at a time, but he can remove multiple blocks of the same colour together. Determine the minimum number of steps in which he can perform this task.

For example, if you remove [red,red] from (white,red,red,white), the resulting array is [white,white].

Note- there are only two colour blocks – red and white

Function description :

Complete the minMoves function in the provided editor. It contains the following parameters:

Parameters:

NameTypeDescription
NIntegerNo. of Wooden blocks
Array[ ]Integer ArrayArray of Blocks.

Input format :

The first line contains an integer n denoting the number of blocks. Each n line denotes the colour of the wooden block .

Constraints :
1<=n<=700
0<=a[i]<=1

Sample input 1 :

4
red
white
white
red

Sample Output 2 :

2

Explanation :

Remove [white,white] first The array will be [red,red] The remaining numbers can  be removed in one strap .

Sample Input 1:

4
white
red
white
red

Sample Output 1:

3

Sample Explanation:
0
The steps are [white,red,white,red]->[red,white,red]->[red,red]->[]. Therefore the answer is 3.

Prime Course Trailer

Related Banners

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

Question 2 :Iron Magnet

Problem Statement  :

We know iron behaves like magnets when all the north and the south sides are placed accordingly in a balanced way while the north comes first and then the south. Now if you are given the distribution of the north and the south poles inside the iron metal piece, you have to say how many swaps is needed to turn it into an iron, if possible, otherwise print -1.

Input Format: A string consisting N and S as north and south poles.
Output Format:
An integer denoting the number of poles will be needed.

Sample Input:
SNNSN

Output:
3

Output Description:
After we balance the iron in the way NSNNSNSS, we will get a piece of metal that will be balanced as a magnet.

Question 3 : Loki’s Mind Stone

Problem Statement  :

Loki, the God of mischief can brainwash any living person by touching him/her with his Mind stone, and has decided to break the avengers (a warrior group) to face into each other, so that they can turn against each other and make Loki’s evil plans easier. Now all the avengers have some amount of strength that is denoted in integers. Loki wants to brainwash the least amount of people possible, because he is lazy. But he wants his team of avengers to win the battle. What is the number of avengers Loki will get brainwashed.

Input Format:
First line contains an integer n, denoting the number of total avengers
the next line contains n space separated integers denoting the power of each avenger.

Output Format:
One line denoting the total number of avengers brainwashed by Loki’s Mind stone.

Constraints:
2<=n<=10^6

Test case:
Sample Input:
6
9 3 1 2 4 2

Sample Output:
2

Output Specifications:
Loki can brainwash the avengers with power 9 and 3, or with 9 and 2, or with 9,4, and the rest will be losing cause cumulative power of rest avengers is less than the brainwashed total power by Loki.

Question 4 : Set Bit

Problem Statement  :

You are given an integer, N. You have to turn it into the binary representation of it, and find out how many set bits are there in the binary representation.

Input Format:
The first line contains the integer.

Output Format:
One line containing an integer denoting the number of setbits.

Constraints:
1<=N<=10^9

Sample Input:
8
Output:
1

Output Description:
8 in binary is 1000.

Question 5 : Death Note

Problem Statement  :

Ryuk, the Shinigami (God of death) had allowed Light Yagami, a school student, to kill as many people as he can by using a death note. But writing the names barely will allow other people to watch them. So he encrypts the names using digits, where a means 1, b means 2 and so on upto z is 26. Now if he gives numbers, there is a communication error because a number string can be decrypted by the death note in various ways and eventually killing them all. If everyone in the world has a unique name, for a given number, how many people can die?
NOTE THAT: There is every possible name in the world with the 26 letters, and capital or small letters is not a problem.

Input format:
A number stream denoting the first name’s encrypted version

Output Format:
Number of people dying by this.

Constraints:
1<=stream length<=10^8

Sample Input: 1267
Sample Output: 3
Output Specification:Two people of the name azg and lfg die.

Sample EY Coding Questions with Answers - Set 2

Question 6: Stock Market

You are given a list of daily prices of a stock. You can buy a stock on one day and sell it later on another day after the day you bought the stock. You can perform the above operation only once. What is the maximum loss possible?

Example

Prices=[10,4,2,9]

The greatest loss is incurred when you buy at a price of 10 and sell at a price of 2.Return the difference:9.

Example

Price=[1,2,3,4] 

The Price went up everyday.Return 0.

Sample Input for Custom Testing

 STDIN                   Function 

———–               ————–

  •    7   →     prices []  size n=7
  •    1 →       prices =[1,8,4,2,10,3,2] 
  •    8
  •    4
  •    2
  •   10
  •    3
  •    2

Sample Output

  •   8

 Explanation

Using zero-based index notation,the correct answer is a[4]-a[6]=10-2=8.There is a greater difference between 10 and 1 but that would imply selling before buying,and short selling is not allowed in this problem.

Question 7: Psychic

Raman was playing a game,  he starts with x coins. Now in every step, he wins and loses and he has to get the money or pay the money as needed. He came in contact with a psychic who can see the future and the Psychic predicted the outcomes after each step. Now Raman wants to start the game with the minimum wage where he doesn’t run out of money.  Help Raman to find what money he should start with. The only rule to keep playing is not going in a credit situation.

Input Format:

  • First line with n, number of steps in the game
  • Next n lines, n integers denoting outcomes of every game. Positive means winning and negative means losing that money.

Output Format:

  • One single integer denoting the minimum amount to start with

Constraints:

  • Number of steps<=10^9
  • -1000<=Money needed in each step<=1000

Sample Input:

4
2
-9
15
2

Sample Output:

7

Explanation:

If he starts with 7 rupees, then after steps : 7 ->9 -> 0-> 15 -> 17.

Question 8: Binary Tree Problem

How will we represent a binary tree? We can use a bracket structure for all of the edges, like (Parentnode , Childnode). Now if we use a node in child node more than once, the tree can not be valid. Same for the parent node, a node can not be taken more than twice in  a graph as a parent node.

Suppose we see this one graph

(P,Q)(P,R)(Q,T)(R,W)(U,V)(Q,S)(R,U)(U,Z)(S,I)(W,Y)

A tree with those edges may be illustrated in many ways.Here are two:

                   P                            P

                /    \                        /     \

              Q      R                   Q      R

            /   \     /    \               /   \    /  \

          S   T   U   W           S    T  U  W

            \        / \     \          /          / \      \

             I     V  Z    Y      I         Z  V    Y

The following is a recursive definition for the S-expression of a tree.

S-exp(node)=(node->val(S-exp(node->first_child))(S-exp(node->second_child))),if node

!NULL=””,node= =NULL

         Where first_child->valval(first_child->val is lexicographically than second_child->val)

This tree can be represented in S-expression in multiple ways.The lexicographically smallest way of expressing it as follows:

P(Q(S(I))(T))(R(U(V)(Z))(W(Y))))

Translate the node-pair representation into its lexicographically smallest S-expression or report any errors that do not conform to the definition of the binary tree.

The List of errors with their codes is as follows: 

Error                               Reason

Code Stopped1                More than 2 children

Code Stopped2                Duplicate Edges

Code Stopped3                Cycle Present(node is direct descendant of more than one node)

Code Stopped4                Multiple Roots

Code Stopped5                Any other error

Constraints:

  1. All node names are single characters in the range ascii[A-Z].
  2. The maximum node count is 26.
  3. There is no specific order to the input (parent,child) pairs.

>Input Format for Custom Testing

>Sample Case 0

Sample Input 0

  • (B,D) (D,E) (A,B) (C,F) (E,G) (A,C)

Sample output 0

  • (A(B(D(E(G))))(C(F)))

Explanation 0

A representation of tree is as follows:

             A

           /    \

         B      C

         /         \

       D           F

      /

     E

    /

  G

>Sample Case 1

Input:

  • (C,E)(D,F)(A,B)(A,C)(B,K)

Output:

  • A(B(K))(C(E)))D(F))

Question 9: Data Packets Streams

A stream of n data packets arrives at a server. This server can only process packets that are exactly 2^n units long for some non-negative integer value of n (0<=n). 

All packets are repackaged in order to the 1 largest possible value of 2^n units. The remaining portion of the packet is added to the next arriving packet before it is repackaged. Find the size of the largest repackaged packet in the given stream. 

Example arriving Packets = [12, 25, 10, 7, 8] 

The first packet has 12 units. The maximum value of 2^n that can be made has 2^n = 2^3 = 8 units because the next size up is 2^n = 2^4 = 16 (16 is greater than 12).   

12 – 8 = 4 units are added to the next packet. There are 4 + 25 = 29 units to repackage, 2^n = 2^4 = 16 is the new size leaving 9 units (29-16 = 9)   

Next packet is 9 + 10 = 29 unists & the maximum units(in 2^n) is 16 leaving 3 units.

3 + 7 = 10 , the max units is 8 Leaving 2 units, and so on. 

The maximum repackaged size is 16 units. 

Returns:

Long : the size of the largest packet that is streamed 

Constraints :

  • 1<=n<=10^5
  • 1<=arriving Packets[i] size<=10^9

Sample case0

Sample input 0:

5 → number of packets=5

12 → size of packets=[13,25,12,2,8]

25

10

2

8

Sample output 0:

16

Question 10: Catch the cheating group

Problem Statement  :

Semester exams are going on for university students. Examiners noticed that a group of people are trying to cheat. They marked students of that group as ‘1’ and students of another group ( who are not cheating ) as ‘0’ 

We can reduce cheating by not allowing students from group 1 to sit together, means no two students from group 1 can sit together. Seatings are marked using above conditions. Your task is to give the seating placement of nth possibility Possibility order from 1 to 10 is given below

[1  10  100  101  1000  1001  1010  10000  10001  10010]

Sample input :

3 → number of test cases

4

6

9

Sample output :

101

1001

10001

Explanation :

4th possibility is 101 

6th possibility is 1001

9th possibility is 10001

FAQs on EY Coding Questions with Solutions

Question 1: In what kind of domain does EY offers job?

EY Consults in domains like : Cyber Security | Data & Analytics | Digital & Emerging Technologies | Technology Solutions Delivery | Technology Transformation | Customer Experience Transformation | IA/Robotics |.

Question 2: What is the Salary offered by EY?
  • For Data Analyst Role : ₹ 4.83 LPA
  • For Senior Data Analyst Role: ₹ 6.32 LPA
Question 3: What is the Eligibility Criteria for EY Hiring Process?

Following points are needed to be kept in mind while applying for EY Recruitment Drive:

  • Eligible Batch: B.Tech, Integrated and M.Tech – CSE-IT, and ECE students.
  • Score: Minimum CGPA 6.5 or equivalent % & in 10th, 12th, Graduation and Post Graduation.
  • No active backlog.
Question 4: What are the steps involved in EY Recruitment Process?

Following points are needed to be kept in mind while applying for EY Recruitment Drive:

  • Eligible Batch: B.Tech, Integrated and M.Tech – CSE-IT, and ECE students.
  • Score: Minimum CGPA 6.5 or equivalent % & in 10th, 12th, Graduation and Post Graduation.
  • No active backlog.
Question 5: What is the EY Test Pattern?
Following Sections are involved in EY Online Assessment:
  1. Quants Section – 22 Questions – 20 Mins
  2. Logical Section – 14 Questions – 18 Mins
  3. Verbal Reasoning – 14 Questions – 14 Mins
  4. Automata Fix – 2 Questions – 45 Mins

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