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
True or False: The differential lock in an AWD-equipped vehicle can be used at any time.
Bingel [31]

the answer would be false

7 0
3 years ago
Read 2 more answers
Briefly explain how a jet moves
sergejj [24]

Answer:

Jet engines move the airplane forward with a great force that is produced by a tremendous thrust and causes the plane to fly very fast. All jet engines, which are also called gas turbines, work on the same principle. The engine sucks air in at the front with a fan. ... Spinning the turbine causes the compressor to spin.

Explanation:

yw

8 0
3 years ago
Compare the use of a low-strength, ductile material (1018 CD) in which the stress-concentration factor can be ignored to a high-
kicyunya [14]

Answer:

Step 1 of 3

Case A:

AISI 1018 CD steel,

Fillet radius at wall=0.1 in,

Diameter of bar

From table deterministic ASTM minimum tensile and yield strengths for some hot rolled and cold drawn steels for 1018 CD steel

Tensile strength

Yield strength

The cross section at A experiences maximum bending moment at wall and constant torsion throughout the length. Due to reasonably high length to diameter ratio transverse shear will be very small compared to bending and torsion.

At the critical stress elements on the top and bottom surfaces transverse shear is zero

Explanation:

See the next steps in the attached image

5 0
3 years ago
How are industries related to systems
REY [17]

Answer:

The industrial systems of the future are seen as complex systems, composed of vast numbers of devices, interacting with each other and with enterprise systems continuously.

summary:

they are related because they ARE a system. well, a type.

hope this helps!! :)

7 0
2 years ago
Water vapor at 100 psi, 500 F and a velocity of 100 ft./sec enters a nozzle operating at steady sate and expands adiabatically t
almond37 [142]

Answer:

a)exit velocity of the steam, V2 = 2016.8 ft/s

b) the amount of entropy produced is 0.006 Btu/Ibm.R

Explanation:

Given:

P1 = 100 psi

V1 = 100 ft./sec

T1 = 500f

P2 = 40 psi

n = 95% = 0.95

a) for nozzle:

Let's apply steady gas equation.

h_1 + \frac{(v_1) ^2}{2} = h_2 + \frac{(v_2)^2}{2}

h1 and h2 = inlet and exit enthalpy respectively.

At T1 = 500f and P1 = 100 psi,

h1 = 1278.8 Btu/Ibm

s1 = 1.708 Btu/Ibm.R

At P2 = 40psi and s1 = 1.708 Btu/Ibm.R

1193.5 Btu/Ibm

Let's find the actual h2 using the formula :

n = \frac{h_1 - h_2*}{h_1 - h_2}

n = \frac{1278.8 - h_2*}{1278.8 - 1193.5}

solving for h2, we have

h_2 = 1197.77 Btu/Ibm

Take Btu/Ibm = 25037 ft²/s²

Using the first equation, exit velocity of the steam =

(1278.8 * 25037) + \frac{(100)^2}{2}= (1197.77*25037)+ \frac{(V_2)^2}{2}

Solving for V2, we have

V2 = 2016.8 ft/s

b) The amount of entropy produced in BTU/ lbm R will be calculated using :

Δs = s2 - s1

Where s1 = 1.708 Btu/Ibm.R

At h2 = 1197.77 Btu/Ibm and P2 =40 psi,

S2 = 1.714 Btu/Ibm.R

Therefore, amount of entropy produced will be:

Δs = 1.714Btu/Ibm.R - 1.708Btu/Ibm.R

= 0.006 Btu/Ibm.R

3 0
3 years ago
Other questions:
  • What are the advantages of using 3D ink jet printing?
    10·1 answer
  • Windmills slow the air and cause it to fill a larger channel as it passes through the blades. Consider a circular windmill with
    10·1 answer
  • A 3-m-high, 11-m-wide rectangular gate is hinged at the top edge at A and is restrained by a fixed ridge at B. Determine the hyd
    12·1 answer
  • Which of the following refers to a full-scale version of a product used to validate performance?
    10·2 answers
  • Which device assists with medical imaging?
    7·2 answers
  • Thoughts about drinking and driving
    12·2 answers
  • Unitate de masura in SI pt F​
    11·1 answer
  • 2. The following segment of carotid artery has an inlet velocity of 50 cm/s (diameter of 15 mm). The outlet has a diameter of 11
    13·1 answer
  • An ideal gas is contained in a closed assembly with an initial pressure and temperature of
    14·1 answer
  • Which thematic group is involved in the transmission and generation of electrical power?
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!