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
What is the perimeter of 14-7 and 3-4
Goshia [24]

Answer:

If you mean two sides are 7 and two sides are 14 then you'd have 42

and for the second you'd have 14

Explanation:

7 + 7 = 14, 14 + 14 = 28, 14 + 28 = 42

3 + 3 = 6, 4 + 4 = 8, 8 + 6 = 14

5 0
3 years ago
Cars going straight or turning right have the right-of-way before you when you're making this type of turn
Paladinen [302]

Answer:

Yes. YES yes yes. Unless you are in Australia or something.

4 0
2 years ago
Removing Shingles from a roof is called a
torisob [31]
D remodeling roofing
7 0
2 years ago
The homogeneous, reversible, exothermic, liquid phase reaction: A근R Is being carried out in a reactor system consisting of an id
baherus [9]

Answer:

attached below

Explanation:

3 0
3 years ago
Consider the rigid pressure vessel containing air in the diagram at the
vredina [299]

Answer:

love you

Explanation:

you do good

8 0
3 years ago
Other questions:
  • Define various optical properties of engineering materials
    11·1 answer
  • What is the air change rate (ACH) for a 100 ft^2 (9.3 m^2) space with a 10 ft (3.0 m) ceiling and an airflow rate of 200 cfm (95
    12·1 answer
  • There are 30 students in a class. Choose the statement that best explains why at least two students have last names that begin w
    12·1 answer
  • Please answer the following questions.
    9·2 answers
  • Write a function called pyramid(height) that acceptsa parameter ""height"". It then prints a pyramid of that height
    10·1 answer
  • Which of the following is a advantage of a chain and sprocket over a pulley and belt system?
    7·1 answer
  • Which actions would the maintenance and operations crews carry out as a building is completed and preparing to open to the publi
    8·2 answers
  • In order to avoid a rollover, what is the highest degree incline one should mow on? 10-degree incline 5-degree incline 30-degree
    15·1 answer
  • Should i show my face?
    8·2 answers
  • Can someone please help!
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!