BNY Mellon Coding Questions and Answers

BNY Mellon Coding Questions with Solutions

On this page, you will find out BNY Mellon Coding Questions and Answers which will help you clear BNY Mellon Online Coding Assessments including BNY Hiring Process.

Go through this page to get all Sample BNY Mellon Coding Questions with Solutions to prepare for Online Coding Assessment and Technical Interviews of the Company.

bny-mellon-coding-questions

BNY Mellon Coding Questions with Solutions

Question 1 : Weird Terminal

Problem Statement : 

(Asked in OnCampus Drive August, 2023)

Here is a weird problem in Susan’s terminal. He can not write more than two words each line, if she writes more than two, it takes only 2 words and the rest are not taken. So she needs to use enter and put the rest in a new line. For a given paragraph, how many lines are needed to be written in Susan’s terminal?

Input Format:
A string as the text to input in the terminal

Output Format:
Number of lines written.

Constraints:
Number of words <=10^7

Sample Input:
How long do you have to sit dear ?

Sample Output:
4

Explanation:
The writing will be:
How long
Do you
Have to
Sit dear ?

Prime Course Trailer

Related Banners

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

Question 2 : Maximum Toys

(Asked in OnCampus Drive August, 2023)

In a toy shop there are a number of toys presented with several various – priced toys in a specific order. You have a limited budget and would like to select the greatest number of consecutive toys that fit within the budget. Given prices of the toys and your budget, what is the maximum number of toys that can be purchased for your child?

Example:

prices=[1,4,5,3,2,1,6]

money=6

All sub arrays that sum to less than or equal to 6 .

length 1:  [1] [4] [5] [3] [2] [1] [6]

length 2:  [1,4] [3,2] [2,1] 

length 3: [3,2,1]

The longest of these or the maximum number of toys that can be purchased is 3.

Function description

Complete the function getMaxToys in the editor below 

getMaxToys has the following parameters:

int prices[n] : the prices of the various toys

int money: the amount of money you can spend on toys 

Returns

Int the maximum number of toys you can purchase 

Constraints

1<=n<=10^5
1<=price[i]<=100
1<=money<=10^6

Sample case 

Sample input 0

7->n=7
1-> price[]=[1,4,5,3,2,1,6]
4
5
3
2
1
6

Sample Output
6 ->money=6

Question 03 : Device Name System

(Asked in OnCampus Drive August, 2023)

Problem statement: Rocky is a software engineer and he is creating his own operating system called “myFirst os”. myFirst os is a GUI (Graphical user interface) based operating system where everything is stored in files and folders. He is facing issues on  creating unique folder names for the operating system . Help rocky to create the unique folder name for it’s os.If folder name already exists in the system and integer number is added at the name to make it unique. The integer added starts with 1 and is incremented by 1 for each new request of an existing folder name. Given a list of folder names , process all requests and return an array of corresponding folder names.

Example 

  • n=5
  • foldername= [‘home’ , ‘myfirst’ ,’downloads’, ‘myfirst’, ‘myfirst’]
  • Foldername[0] = ‘home’ is unique.
  • Foldername[1] = ‘myfirst’ is unique.
  • foldername [2] =’downloads’ is unique.
  • Foldername[3] =’myfirst’ already exists in our system. So Add1 at the end of the folder name i.e foldername[3] =”myfirst1″
  • Foldername[4 ]=’myfirst’ also already exists in our system.So add 2 at the end of the folder name i.e. foldername[4]=”myfirst2″.

Function description 

  • Complete the function folderNameSystem In the editor below
  • folderNameSystem has the following parameters
  • string foldername[n]: an array of folder name string in the order requested

Returns:

  • String[n]:  an array of strings usernames in the order assigned

Constraints

  •     1<=n<=10^4
  •     1<=length of foldername[i]<20
  •     foldername[i] contains only lowercase english letter in the range ascii[a-z]

Input Format:

  • The first line contains an integer n , denoting the size of the array usernames Each line i of the n subsequent lines (where i<=0<=n) contains a string usernames[i] representing a username request in the order received.

Sample case 0

  • 4
  • home 
  • download
  • first
  • first

Sample Output 0

  • home
  • download
  • first
  • first1

Explanation 0

  •    foldername[0] = ‘home’ is unique
  •    foldername[1]=’download’ is unique
  •    foldername[2]= ‘first’ is unique
  •    foldername[3]=’first’ is already existing . so add 1 to it and it become first1

Question 4: Amusement park

(Asked in OnCampus Drive July, 2023)

Problem Statement – Akshay loves to go to WONDERLA , an amusement park. They are offering students who can code well with some discount. Our task is to reduce the cost of the ticket as low as possible.

The cost of tickets can be removed by removing the digits from the price given. They will give some k turns to remove the digits from the price of the ticket. Your task is to help Akshay in coding a program that can help him to reduce the cost of a ticket by removing the digits from its price and getting the maximum possible discount.

Note – You cannot make the cost of a ticket zero. For eg -: If the cost of a ticket is 100, and you have 2 turns to reduce the price, the final price will be 1 and not zero.

Constraints:

  • 1 <= number of tickets <= 10^5
  • 1 <= K < Number of digits in Price of ticket

Input Format for Custom Testing:

  • The first line contains a string,Tickets, denoting the given cost of each ticket.
  • The next line contains an integer, K, denoting the number of tickets that is to be removed.

Sample Cases:

  • Sample Input 1
    203
    2
  • Sample Output 1
    0

Question 05 : PrepInsta Name : Borrow Number

(Asked in OnCampus Drive July, 2023)

Problem statement : You have two numbers number1 and number2, your job is to check the number of borrow operations needed for subtraction of number1 from number2. If the subtraction is not possible
then return the string not possible.

Example :

  • 754
  • 658

Answer :

  • 2
  • 654
  • 666

Question 6 :Vampire Battle (R->Medium)

(Asked in OnCampus Drive July, 2023)

Problem statement :

Stephan is a vampire. And he is fighting with his brother Damon. Vampires get energy from human bloods, so they need to feed on human blood, killing the human beings. Stephan is also less inhuman, so he will like to take less life in his hand. Now all the people’s blood has some power, which increases the powers of the Vampire. Stephan just needs to be more powerful than Damon, killing the least human possible. Tell the total power Steohan will have after drinking the bloods before the battle.
Note that: Damon is a beast, so no human being will be left after Damon drinks everyone’s blood. But Stephan always comes early in the town.

Input Format :
First line with the number of people in the town, n.
Second line with a string with n characters, denoting the one digit power in every blood.

Output Format :
Total minimum power Stephan will gather before the battle.

Constraints :
n<=10^4

Sample input :
6
093212

Sample output:
9

Explanation :
Stephan riches the town, drinks the blood with power 9. Now Damon cannot reach 9 by drinking all the other bloods.

Question 7: Array Subarray

(Asked in OnCampus Drive July, 2023)

Problem Statement: You are given an array, You have to choose a contiguous subarray of length ‘k’, and find the minimum of that segment, return the maximum of those minimums.

Sample input :

  • 1 → Length of segment x =1
  • 5 → size of space n = 5
  • 1 → space = [ 1,2,3,1,2]
  • 2
  • 3
  • 1
  • 2

Sample output :

  • 3

Explanation :

  • The subarrays of size x = 1 are [1],[2],[3],[1], and [2],Because each subarray only contains 1 element, each value is minimal with respect to the subarray it is in. The maximum of these values is 3. Therefore, the answer is 3

Question 8 : Coin Game (R->Medium)

(Asked in OnCampus Drive July, 2023)

Problem Statement  :

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 9 : Coloured Zenga

(Asked in OnCampus Drive July, 2023)

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.

Question 10 :A Good Prime Number

(Asked in OnCampus Drive July, 2023)

Problem Statement  :

A prime number is a number which is divisible by one and itself. Also a number is called a good  prime number if the sum of its digits is a prime number. For example a number 23 is a good prime number because the sum of 2 and 3 ( 2+3=5) is 5 which is a prime number. You are given an integer K. Your task is to find the kth good prime number that is greater than a provided number N.

For example , 232 is a good prime number since the sum of all digits is 7 which is a prime number whereas 235 is not a good prime number.

Input format :

  • The first line contains an integer N.
  • The next line contains an integer K.

Output format :

A single integer which is a Kth good prime number that is greater than a provided number N.

Constraints :

  • 1<=N<=10^5
  • 1<=K<<=10^5

Sample Input 1:

4  4

Sample Output 1:

12

Explanation :

Good prime numbers starting from 4 are 5,7,11(1+1=2 which is prime number),12(1+2=3 which is prime number),14(1+4=5 which is a prime number) and so on. Because the sum of digits of an individual number is a prime number And 4 th good prime number is 12 in this series.Hence the output is 12. 

Sample Input 2:

17  5

Sample Output 2:

29

Explanation :

Good prime numbers starting from 17 are 20,21,23,25,29…and the 5th prime number is 29.Hence the output is 29.

FAQs on BNY Mellon Coding Questions

Question 1: What questions are asked in coding test?

DSA Based Coding Questions are Included in both BNY Mellon Coding Test.

Question 2: What is BNY Mellon Code Diva ?

BNY Mellon Code Diva is a hiring challenge consist of 2 Technical Test conducted by BNY Mellon, to hire Women.

Question 3: What are the benefits of BNY Mellon Code Diva?

After clearing BNY Mellon Code Vita selected Women will get Tech Internships and Full Time Positions.

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