











EY Coding Questions
EY Coding Questions
EY Coding Questions discussed on this page are a part of Automata Fix which is one of the section of EY Online Written Assessment. It is all together a different section that is specifically designed to test the coding skills of a student who wishes to be a part of Ernst & Young as a Data Analyst. The Job Role is in Service Line: Consulting (Technology Consulting & Business Consulting)


About EY
Through assurance, varied EY teams in more than 150 countries help customers develop, change, and operate thanks to data and technology.
EY teams work across assurance, consulting, law, strategy, tax, and transactions to discover fresh approaches to the challenging problems facing our world today.
Prime Course Trailer
About EY Recruitment Process
- Quantitative Aptitude
- Logical Reasoning
- Verbal Reasoning
- Automata Fix
EY | Related Information |
---|---|
Batch | 2023 |
Course | Eligible Batch – B.Tech, Integrated and M.Tech – CSE-IT, and ECE students. |
Education |
|
Cost to Company (CTC) |
|
EY is hiring for the Job Profile - Senior Analyst and and Rs. 6,37,173 PA.
EY Online Assessment
EY | Number of Questions | Time |
---|---|---|
Verbal Reasoning | 22 | 18 mins |
Quantitative Aptitude | 14 | 14 mins |
Logical Reasoning | 14 | 20 mins |
Automata Fix | 2 | 45 mins |
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
EY Automata Fix Section
Automata Fix: This section is considered as one of the toughest section. You will have to choose one language of your choice and then solve the question.
- C
- C++
- Java
- Python
Important Note:
- Number of Questions -2 Question
- Total Time Limit – 45 mins
- Difficulty – High
EY Coding Questions
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:
Name | Type | Description |
---|---|---|
N | Integer | No. of Wooden blocks |
Array[ ] | Integer Array | Array 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.
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector < string > arr(n); for (int i = 0; i < n; i++) cin >> arr[i]; int a = 0, b = 0; bool start = false; for (int i = 0; i < n; i++) { if (arr[i] == "white") { if (!start) { start = true; } } else { if (start) { a++; start = false; } } } if (start) a++; start = false; for (int i = 0; i < n; i++) { if (arr[i] == "red") { if (!start) { start = true; } } else { if (start) { b++; start = false; } } if (start) b++; } cout << min(a + 1, b + 1) << endl; return 0; }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String arr[] = new String[n]; for (int i = 0; i < n; i++) arr[i] = sc.next(); int a = 0, b = 0; boolean flag = false; for (int i = 0; i < n; i++) { if (arr[i].equals("white")) { if (!flag) flag = true; } else { if (flag) { a++; flag = false; } } } if (flag) a++; flag = false; for (int i = 0; i < n; i++) { if (arr[i].equals("red")) { if (!flag) flag = true; } else { if (flag) { b++; flag = false; } } if (flag) b++; } System.out.println(Math.min(a + 1, b + 1)); } }
n = int(input()) arr = [] for i in range(n): arr.append(input()) a, b = 0, 0 start = False for i in range(n): if arr[i] == "white": if not start: start = True else: if start: a += 1 start = False if start: a += 1 start = False for i in range(n): if arr[i] == "red": if not start: start = True else: if start: b += 1 start = False if start: b += 1 print(min(a + 1, b + 1))
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.
#include <bits/stdc++.h> using namespace std; int main() { string s; int ans = 0, k = 0; cin >> s; for (auto i: s) { if (i == 'N') k++; else k--; if (k < 0) { k++; ans++; } } ans += k; cout << ans; }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); int res = 0, j = 0; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == 'N') j++; else j--; if (j < 0) { j++; res++; } } res = res + j; System.out.println(res); } }
s = input() ans = 0 if s[0] != "N": ans += 1 s = "N" + s print(ans + abs(s.count("N") - s.count("S")))
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.
#include <bits/stdc++.h> using namespace std; map < int, int > m; int main() { int n, sum = 0, sum2 = 0, ans = 0; cin >> n; vector < int > v(n); for (int i = 0; i < n; i++) { cin >> v[i]; sum += v[i]; } sort(v.begin(), v.end(), greater < int > ()); sum /= 2; while (sum2 <= sum && ans < n) { sum2 += v[ans]; ans++; } cout << ans; }
import java.util.*; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int arr[] = new int[n]; int sum = 0; for (int i = 0; i < arr.length; i++) { arr[i] = sc.nextInt(); sum = sum + arr[i]; } Arrays.sort(arr); int sum1 = 0, count = 0; for (int i = arr.length - 1; i >= 0; i--) { sum1 = sum1 + arr[i]; sum = sum - arr[i]; count++; if (sum1 > sum) break; } System.out.println(count); } }
n = int(input()) arr = list(map(int, input().split())) s = sum(arr) arr.sort(reverse=True) dup, sum1, ans = 0, 0, 0 for i in arr: dup += i sum1 = s - dup ans += 1 if sum1 < dup: break print(ans)
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.
#includeusing namespace std; int main() { int n, ans = 0; cin >> n; while (n) { n &= (n - 1); ans++; } cout << ans; }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int count = 0; while (n != 0) { if ((n & 1) == 1) count++; n = n >> 1; } System.out.println(count); } }
n = int(input()) ans = 0 while n: n &= n - 1 ans += 1 print(ans)
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.
#include <bits/stdc++.h> using namespace std; string s; int ans; void func(int i, int n) { if (i == n - 1 || i == n) { ans++; return; } if (s[i] == '1') func(i + 2, n); else if (s[i] == '2' && s[i + 1] < '7') func(i + 2, n); func(i + 1, n); } int main() { ans = 0; cin >> s; func(0, s.length()); cout << ans; }
import java.util.*; class Main { static String s; static int ans; public static void func(int i, int n) { if (i == n - 1 || i == n) { ans++; return; } if (s.charAt(i) == '1') func(i + 2, n); else if (s.charAt(i) == '2' && s.charAt(i + 1) < '7') func(i + 2, n); func(i + 1, n); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); s = sc.next(); func(0, s.length()); System.out.println(ans); } }
def solve(s, n): if n == 0 or n == 1: return 1 ans = 0 if s[n - 1] > "0": ans = solve(s, n - 1) if s[n - 2] == "1" or (s[n - 2] == "2" and s[n - 1] < "7"): ans += solve(s, n - 2) return ans s = input() print(solve(s, len(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
Login/Signup to comment