answer.
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]
2 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]2 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]2 years ago
3 0

Answer:

Please look at attachment. Thanks

Guest1 year 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
Water at 70 kPa and 1008C is compressed isentropically in a closed system to 4 MPa. Determine the final temperature of the water
Nikitich [7]

Answer:

The answer is "909.3928  KJ".

Explanation:

70 \ kPa  \ \ and \ \ 100^{\circ}C \\\\s_i= 7.56162\ \frac{kJ}{kgK}\\\\u_i= 2509.39 \ \frac{kJ}{kg}\\\\

The method is isentropic since the cylinders are shielded.

Calculating the work:

w= u_2-u_i \\\\

   = 3418.7728-2509.38 \\\\=909.3928 \ KJ

3 0
2 years ago
Problem 5) Water is pumped through a 60 m long, 0.3 m diameter pipe from a lower reservoir to a higher reservoir whose surface i
kap26 [50]

Answer:

\epsilon = 0.028*0.3 = 0.0084

Explanation:

\frac{P_1}{\rho} + \frac{v_1^2}{2g} +z_1 +h_p - h_l =\frac{P_2}{\rho} + \frac{v_2^2}{2g} +z_2

where P_1 = P_2 = 0

V1 AND V2  =0

Z1 =0

h_P = \frac{w_p}{\rho Q}

=\frac{40}{9.8*10^3*0.2} = 20.4 m

20.4 - (f [\frac{l}{d}] +kl) \frac{v_1^2}{2g} = 10

we know thaTV  =\frac{Q}{A}

V = \frac{0.2}{\pi \frac{0.3^2}{4}} =2.82 m/sec

20.4 - (f \frac{60}{0.3} +14.5) \frac{2.82^2}{2*9.81} = 10

f  = 0.0560

Re =\frac{\rho v D}{\mu}

Re =\frac{10^2*2.82*0.3}{1.12*10^{-3}} =7.53*10^5

fro Re = 7.53*10^5 and f = 0.0560

\frac{\epsilon}{D] = 0.028

\epsilon = 0.028*0.3 = 0.0084

4 0
2 years ago
Radioactive wastes are temporarily stored in a spherical container, the center of which is buried a distance of 10 m below the e
puteri [66]

Given:

outer radius, R' = 10 m

inner diameter, d = 2 m

inner radius, R = \frac{d}{2} = 1 m

surface temperature, T' = 20^{\circ}C

Thermal conductivity of soil, K = 0.52 W/mK

Solution:

To calculate the thermal temperature of conductor, T, we know amount of heat, Q is given by :

Q =  \frac{T - T'}{\frac{R' - R}{4\pi KRR'}}

500 =  (T - 20)\frac{4\pi \times0.52\times 1\times 10}{10 - 1}

T = 68.86 +20 = 88.865^{\circ}C  

Therefore, outside surface temperature is 88.865^{\circ}C  

4 0
2 years ago
Consider film condensation on a vertical plate. Will the heat flux be higher at the top or at the bottom of the plate? Why?
STALIN [3.7K]

Answer:

During film condensation on a vertical plate, heat flux at the top will be higher since the thickness of the film at the top, and thus its thermal resistance, is lower.

Explanation:

https://www.docsity.com/pt/cengel-solution-heat-and-mass-transfer-2th-ed-heat-chap10-034/4868218/

https://arc.aiaa.org/doi/pdf/10.2514/1.43136

https://arxiv.org/ftp/arxiv/papers/1402/1402.5018.pdf

8 0
2 years ago
A 20 dBm power source is connected to the input of a directional coupler having a coupling factor of 20 dB, a directivity of 35
lukranit [14]

Answer:

P_O = 0.989 watt = 19.9 dBm

Explanation:

Given data:

P_1 power = 20 dBm  = 0.1 watt

coupling factor is 20dB

Directivity = 35 dB

We know that

coupling factor = 10 log \frac{P_1}{P_f}

solving for  final power

20 = 10 log\frac{P_1}{P_f}

2 = log \frac{P_1}{P_f}

100 = \frac{0.1}{P_f}

P_f = 0.001 watt = 0 dBm

Directivity D =  10 \frac{P_f}{P_b}

35 = 10 \frac{0.001}{P_b}

P_b = 3.162 \times 10^{-7} wattt

output Power  = P_1 -P_f - P_b

                       = 0.1 - 0.001 - 3.162 \times 10^{-7}

P_O = 0.989 watt = 19.9 dBm

6 0
2 years ago
Other questions:
  • The pressure at any point in a static fluid depends only on the Select one a)- depth, surface pressure, and specific weight. b)-
    11·1 answer
  • a. Replacing standard incandescent lightbulbs with energy-efficient compact fluorescent lightbulbs can save a lot of energy. Cal
    9·1 answer
  • A petrol engine produces 20 hp using 35 kW of heat transfer from burning fuel. What is its thermal efficiency, and how much powe
    14·1 answer
  • Pam Jones worked for 41 years at the same company and had positive performance ratings and personnel records. She needed a calcu
    9·1 answer
  • Gina is about to use a fire extinguisher on a small fire. What factor determines the type of extinguisher she should use
    9·2 answers
  • A joining process in which a filler metal is melted and distributed by capillary action between faying surfaces, the base metals
    12·1 answer
  • A mass of 12 kg saturated refrigerant-134a vapor is contained in a piston-cylinder device at 240 kPa. Now 300 kJ of heat is tran
    8·1 answer
  • Five Kilograms of continuous boron fibers are introduced in a unidirectional orientation into of an 8kg aluminum matrix. Calcula
    9·1 answer
  • Thermal energy generated by the electrical resistance of a 5-mm-diameter and 4-m-long bare cable is dissipated to the surroundin
    12·1 answer
  • While at a concert you notice five people in the crowd headed in the same direction. Your tendency to group them is due to? *
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!