1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alona [7]
3 years ago
9

Write a function: def solution (S) that, given a string S of letters "L" and "R", denoting the types of shoes in line (left or r

ight), returns the maximum number of intervals such that each interval contains an equal number of left and right shoes. For example, given S "RLRRLLRLRRLL", the function should return 4, because S can be split into intervals: "RL, "RRLL", "RL" and "RRLL". Note that the intervals do not have to be of the same size.

Engineering
3 answers:
KiRa [710]3 years ago
7 0

Answer:

# The function solution is defined with String S as argument

def solution(S):

   # number of letter R is assigned to letterRcount

   # it is initialized to 0

   letterRcount = 0

   # number of letter L is assigned to letterLcount

   # it is initialized to 0

   letterLcount = 0

   # the total count of 'RL' is assigned to total_count

   total_count = S.count("RL")

   # for loop that goes through the string

   for letter in S:

       # if the letter is R, it continue

       if(letter == 'R'):

           continue

       # once it continue, it will increment letterRcount

           letterRcount += 1

       # else if the letter is L, it will increment letterLcount

       elif (letter == 'L'):

           letterLcount += 1

   # if letterRcount is equals to letterLcount, total_count will be incremented

   if(letterRcount == letterLcount):

       total_count += 1

   # the value of total_count is returned

   return total_count

   

# the solution function is called with a string arguments

print(solution("RLRRLLRLRRLL"))

Explanation:

The program is written in python and well commented. A sample of program output is attached.

denpristay [2]3 years ago
3 0

Answer:

Please look at attachment. Thanks

Casper2 years ago
0 0

This is the correct answer for all test cases
def solution(S):
rcount=0
lcount=0
count_total=0
for c in S:
if (c=='R'):
rcount+=1
elif (c=='L'):
lcount+=1
if( rcount==lcount):
count_total+=1
rcount=0
lcount=0
return count_total

You might be interested in
Select the right answer<br>​
Kruka [31]

Answer:

for 1st question the answer is 5th option.

for 2nd question the answer is 2nd option

hope it helps you mate

please mark me as brainliast

5 0
3 years ago
I want to solve the question
DedPeter [7]

Answer:

yes.

Explanation:

5 0
3 years ago
Which explanation best identifies why the company in the following scenario has decided against investing in solar energy?
pickupchik [31]

Answer:

The company found the cost of the required photovoltaic cells too expensive.

Explanation:

Solar energy can be used as an alternative source of supply for fuel. Solar energy is a renewable source of energy, that is it keeps on replenishing every day. Also solar energy does not require a lot of maintenance.

The cost required is starting a solar system is very high because one needs to buy solar panel, photovoltaic cells for batteries, inverters and so on.

From the question, the company decided against solar energy for the time being. This means that probably in the future they might consider it. Therefore it is as a result of the economic situation of the company that they have not set up a solar system because the cost of the required photovoltaic cells too expensive.

8 0
3 years ago
What causes a boat to float? My questions are super easy. So you can follow me if you like easy question.
marin [14]
Boats float because the gravity is acting down on it and the buoyant force is acting up on the ship.
6 0
3 years ago
Read 2 more answers
Technician A says the small base circuit of a transistor controls current flow. Technician B says the small emitter circuit cont
Amiraneli [1.4K]

Answer:

A

Explanation:

6 0
3 years ago
Other questions:
  • In Victorious, when everyone was trapped in the RV, who wasn’t? And what were they doing??
    10·1 answer
  • Please answer the following questions.
    9·2 answers
  • Air in a rigid tank is initially at 320 K and 130 kPa. Heat is added until the final pressure is 438 kPa. What is the change in
    9·1 answer
  • Importance of civil engineering in nepal?​
    10·1 answer
  • Python lists are commonly used to store data types. Lists are a collection of information typically called a container. Think of
    5·1 answer
  • 9.21 A household oven door of 0.5-m height and 0.7-m width reaches an average surface temperature of 32℃ during operation. Estim
    8·1 answer
  • Con que otro nombre se le conoce a los delitos informaticos
    5·1 answer
  • For many clients, a decision is based primarily on time and money, which are the two most abundant
    10·2 answers
  • What do Engineering Systems achieve?
    8·1 answer
  • Suppose a contract states that the designer should bear the responsibility if substantial differences were found between the des
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!