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]
4 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]4 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]4 years ago
3 0

Answer:

Please look at attachment. Thanks

Casper3 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 primary damage control telephone circuit for
user100 [1]

Answer:

hsyghcjqg9ug9duyssatayfjzurldh

6 0
2 years ago
What is an example of a class 2 lever?
9966 [12]

Answer:

A wheelbarrow, a bottle opener, and an oar are examples of second class levers

6 0
3 years ago
Read 2 more answers
Select the correct answer. Ruby wants to create a cube puzzle game. For that she has to create a cube. Which drafting tool do yo
Alexxx [7]

Answer:

D. a triangle and a T-Square

Explanation:

A T-Square is the best drawing tool to create squares. You would need a squares to create cubes.

3 0
3 years ago
Line(s) indicates passing is allowed if there are no oncoming cars.
anygoal [31]
Broken yellow b/c you can’t pass on a double solid yellow
5 0
4 years ago
What are the inputs, outputs and side effects of a PSP?
Kipish [7]

Answer:

Side effects - sudden loss of balance/ repeated falls

Outputs - sever sickness and could me factual

Inputs/corrections of this- medications and experimental treatments to help slow the process of deterioration

5 0
3 years ago
Other questions:
  • The popularity of orange juice, especially as a breakfast drink, makes it an important factor in the economy of orange-growing r
    14·1 answer
  • A ____ is marked by two sets of double yellow lines, with each set having a broken line on the inside, and a solid line on the o
    15·2 answers
  • Water at 20 °C is flowing with velocity of 0.5 m/s between two parallel flat plates placed 1 cm apart. Determine the distances f
    5·1 answer
  • Finally you will implement the full Pegasos algorithm. You will be given the same feature matrix and labels array as you were gi
    12·1 answer
  • Using the idea of mass and change of speed... could a bowling ball be thrown so fast that it has the same force as a car driving
    7·1 answer
  • As an engineer which types of ethical issues or problem you can face in industrial environment.
    8·1 answer
  • What differentiates the master builder approach prior to the Renaissance from later approaches? Projects do not depend on indivi
    14·1 answer
  • Write down about the water source selection criteria​
    9·1 answer
  • Connect wires to make the correct logic outputs.
    12·1 answer
  • Why is communication one of the most important aspects of an engineer's job?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!