Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with Python code for best performance 1 . CountBananas Calculate how many times you can print the word BANANA using the letters given

Need help with Python code for best performance
1. CountBananas Calculate how many times you can print the word "BANANA" using the letters given in string S.
Task description
A string S made of uppercase English letters is given. In one move,six letters forming the word "BANANA" (one 'B', three 'A's and two 'N's) can be deleted from S. What is the maximum number times such a move can be applied to S?
Write a function:
function solution(S: string): number;
that, given a string S of length N, returns the maximum number of moves that can be applied.
Examples:
1. Given S = "NAABXXAN", the function should return 1.
NAABXXAN
2. Given S = "NAANAAXNABABYNNBZ", the function should return 2.
NAANAAXNABABYNNBZ
NAAXNABYNBZ
XBYNZ
3. Given S = "QABAAAWOBL", the function should return 0.
QABAAAWOBL
Write an efficient algorithm for the following assumptions*
. N is an integer within the range [1..100,000); string S is made only of uppercase letters (A-Z).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions