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
Question
Leto [7]

Answer:

True

Explanation:

The CNC is the primary interface between the machine operator and the machine.

4 0
2 years ago
What is your name in face book​
nekit [7.7K]

Answer:

Why do you want to know...?

4 0
3 years ago
Read 2 more answers
Time management is a learned behavior.<br> True<br> False
larisa [96]

Answer:

true

Explanation:

3 0
3 years ago
Read 2 more answers
Which of the following describes a logic bomb?
dem82 [27]

Answer:

A piece of code hidden in spread sheet

8 0
3 years ago
How does a truth tables impact the development of a completed circuit? Make sure to use as many keywords as possible to back up
WINSTONCH [101]

Answer:

it is one this so the key word are pfp tpf htf pfp

Explanation:

3 0
3 years ago
Other questions:
  • The roof of a refrigerated truck compartment consists of a layer of foamed urethane insulation (t2 = 21 mm, ki = 0.026 W/m K) be
    14·1 answer
  • Consider an area-source box model for air pollution above a peninsula of land. The length of the box is 15 km, its width is 80 k
    8·1 answer
  • The Bureau of Labor and Statistics predicted that the field of biomedical engineering would increase by 62 percent over the comi
    5·1 answer
  • People with skills and training in areas such as marketing or accounting are an important part of the manufacturing industry.
    11·1 answer
  • The seers were of the opinion that_____ . *
    14·1 answer
  • simple Brayton cycle using air as the working fluid has a pressure ratio of 10. The minimum and maximum temperatures in the cycl
    7·1 answer
  • Technician A says that a circuit with continuity reads 0 ohms. Technician B says that an open circuit reads 0 ohms. Who is corre
    12·1 answer
  • A construction crew lifts approximately 400 lb. of material several times during a day from a flatbed truck to a 25 ft. rooftop.
    10·1 answer
  • Which type of Artificial Intelligence (AI) can repeatedly perform tasks of limited scope?
    12·1 answer
  • To meet the needs of a client, what is best for an interior designer to do?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!