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
Find: factor of safety (n)for point A and B by using both MSS and DE (you can neglect shear stress due to shear force and also n
gladu [14]

Answer:

Hello your question is incomplete attached below is the complete question

Answer : Factor of safety for point A :

i) using MSS

(Fos)MSS =  3.22

ii) using DE

(Fos)DE = 3.27

Factor of safety for point B

i) using MSS

(Fos)MSS =  3.04

ii) using DE

(Fos)DE = 3.604

Explanation:

Factor of safety for point A :

i) using MSS

(Fos)MSS =  3.22

ii) using DE

(Fos)DE = 3.27

Factor of safety for point B

i) using MSS

(Fos)MSS =  3.04

ii) using DE

(Fos)DE = 3.604

Attached below is the detailed solution

8 0
3 years ago
Technician A says that the carpet padding is designed to help reduce noise and vibrations.
Firdavs [7]

Answer:

Technicians A is right for the answer

4 0
2 years ago
‏What is the potential energy in joules of a 12 kg ( mass ) at 25 m above a datum plane ?
Virty [35]

Answer:

E = 2940 J

Explanation:

It is given that,

Mass, m = 12 kg

Position at which the object is placed, h = 25 m

We need to find the potential energy of the mass. It is given by the formula as follows :

E = mgh

g is acceleration due to gravity

E=12\times 9.8\times 25\\\\E=2940\ J

So, the potential energy of the mass is 2940 J.

3 0
3 years ago
A body weighs 50 N and hangs from a spring with spring constant of 50 N/m. A dashpot is attached to the body. If the body is rai
lbvjy [14]

Answer:

a) 3.607 m

b) 1.5963 m

Explanation:

See that attached pictures for explanation.

3 0
2 years ago
The maximum stress that a bar will withstand before failing is called • Rapture Strength • Yield Strength • Tensile Strength • B
konstantin123 [22]

Answer: Rupture strength

Explanation: Rupture strength is the strength of a material that is bearable till the point before the breakage by the tensile strength applied on it. This term is mentioned when there is a sort of deformation in the material due to tension.So, rupture will occur before whenever there are chances of failing and the material is still able to bear stresses before failing.  

7 0
3 years ago
Other questions:
  • Members of the student council have been asked by their
    5·1 answer
  • Which phrase best describes a safety-critical system? A. a system that faces a very high risk of failure B. a system isolated fr
    13·1 answer
  • A metallic material with yield stress of 140 MPa and cross section of 300 mm x 100 mm, is subjected to a tensile force of 8.00 M
    12·1 answer
  • Write a function named "total_population" that takes a string then a list as parameters where the string represents the name of
    5·1 answer
  • One kilogram of air, initially at 5 bar, 350 K, and 3 kg of carbon dioxide (CO2), initially at 2 bar, 450 K, are confined to opp
    14·1 answer
  • A nozzle receives an ideal gas flow with a velocity of 25 m/s, and the exit at 100 kPa, 300 K velocity is 250 m/s. Determine the
    14·1 answer
  • ¿Cómo nos podría ayudar una hoja de cálculo en nuestro estudio?
    11·1 answer
  • 1. Describe simply what will happen to an airplane in flight in the following conditions:
    6·1 answer
  • List six clues that indicates that you are approaching an intersection
    10·1 answer
  • Part A Identify the zero-force members in the truss. (Figure 1) (Hint: Use both visual inspection and analysis.) Check all that
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!