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
The flowrate through a rectangular channel is 20 cfs. The upstream width of the channel is 10 ft, and the depth of the water in
Liula [17]

To solve this problem we will use the Froude number that relates the Forces of Inertia with the Forces of Gravity. There will be jump in the downstream only if Froude Number (Fr) is greater than 1 at upstream. Our values are given as,

Q = 20cfs\\w= 10ft\\D= 1ft

Then the velocity would be:

V = \frac{Q}{wD}V = \frac{20}{10*1}V = 2ft/s

The number of Froude is given as,

Fr = \frac{V}{gD}^{1/2}

Where,

V = Velocity

g = Gravity

D = Diameter

Replacing we have that

Fr = \frac{2}{32.2}^{1/2}\\Fr = 0.352\\Fr

There will be no Jump, correct answer is B.

5 0
3 years ago
A reversible compression of 1 mol of an ideal gas in a piston/cylinder device results in a pressure increase from 1 bar to P2 an
Mashutka [201]

Answer:

attached below

Explanation:

6 0
3 years ago
Which contemporary jazz artist was one of the first to use a synthesizer in their recording
ivolga24 [154]

Answer:

In this era, Sun Ra was among the first of any musicians to make extensive and pioneering use of synthesizers and other various electronic keyboards; he was given a prototype Minimoog by its inventor, Robert Moog.

Explanation:

3 0
2 years ago
Degreasers can be broken down into two main categories
Alex17521 [72]
Degreasers can be categorized to be either water-based or solvent-based.
5 0
3 years ago
Read 2 more answers
Consider a catchment that has a total area of 2.1 acres. Runoff from the entire catchment flows into one pipe inlet. Part of the
sattari [20]

Find the given attachment

5 0
3 years ago
Other questions:
  • Propane burns at an equivalence ratio (ER) of 0.6, determine actual air-fuel ratio. If excess air is 5%, what will be the actual
    8·1 answer
  • A transmitter has an output power of 0.1mW while the fiber has coupling loss of 12dB, attenuation of
    11·1 answer
  • An architect position requires an internship or residency true or false
    5·1 answer
  • When a power of 10 moves from the numerator to the denominator, the sign of the exponent changes true or false
    5·1 answer
  • In the given circuit, V(t)=12cos(2000t+45)V, R1=R2=2Ω, L1=L2=L3=3mH and C1=250μF. You are required to find the Thevenin equivale
    7·1 answer
  • For a very rough pipe wall the friction factor is constant at high Reynolds numbers. For a length L1 the pressure drop over the
    9·1 answer
  • Who ever is here first get brainliest
    13·1 answer
  • One end of a___ is tapered to a dull point and is used to align larger holes such as
    10·1 answer
  • Based on your client's request, you will now create a sketch model of your designed pet toy. You will use your technical sketch
    7·1 answer
  • Ur are mean bryce lolololololololollolollolololol
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!