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
Under the right conditions, it is possible, due to surface tension, to have metal objects float on water. Consider placing a sho
stiv31 [10]

Answer:

D = 0.060732 in

Explanation:

given data

sp. wt. = 500 lb/ft³

diameter = 0.036 in

solution

we get here maximum diameter of rod that is express as

D = \sqrt{\frac{8 \sigma }{\pi y}}   ......................1

here \sigma surface tension of water at 60⁰f  = 5.03 × 10^{-3}  lb/ft and y = 500 lb/ft³

so put here value and we will get

D = \sqrt{\frac{8 \times 5.03 \times 10^{-3} }{\pi \times 500}}

D = 0.005061 ft

D = 0.060732 in

4 0
3 years ago
• ¿Qué les reclamó Dios al pueblo?<br> • ¿Qué consecuencias hubo?
HACTEHA [7]

a quien alos israelitas

8 0
3 years ago
The selective thickness shims are measured with a(n): Group of answer choices hydraulic press. outside micrometer. dial indicato
alexgriva [62]

The selective thickness shims are measured with an outside micrometer.

<h3>What is a micrometer?</h3>

It should be noted that a micrometer simply means an instrument for making precise linear measurement of dimensions.

In this case, the selective thickness shims are measured with an outside micrometer.

Learn more about micrometer on:

brainly.com/question/2176082

#SPJ12

7 0
3 years ago
An elastic cable is to be designed for bungee jumping from a tower 130 ft high. The specifications call for the cable to be 85 f
azamat

Answer:

<em>a) The spring constant is 50 lb/ft</em>

<em>b) The man is 26.3 ft close to the ground.</em>

<em></em>

Explanation:

Height of tower is 130 ft

Specification calls for a cable of length 85 ft

the maximum this length stretches is 100 ft when subjected to a load of 750 lb

The extension of the cable is calculated from the formula from Hooke's law

F = kx

where F is the load or force on the cable

k is the spring constant of the cable

x is the extension on the cable

a) The extension on the cable is

x = 100 ft - 85 ft = 15 ft

substituting into the formula above, we'll have

750 = k*15

k = 750/15 = <em>50 lb/ft</em>

b) for a 185 lb man, jumping down will give an extension gotten as

F = kx

185 = 50*x

x = 185/50 = 3.7 ft

The total length of the cable will be extended to 100 ft + 3.7 ft = 103.7 ft

closeness to the ground = 130 ft - 103.7 ft =<em> 26.3 ft</em>

3 0
3 years ago
Which statement about direct-mail messages is most accurate? Group of answer choices Direct mail is an effective channel for per
torisob [31]

Answer:

Option A

Direct mail is an effective channel for personalized, tangible, three-dimensional messages that are less invasive than telephone solicitations

Explanation:

In modern days, we've seen email marketing hence option B that "Today's companies no longer send direct-mail messages to market their products or services; they rely exclusively on electronic media instead." These companies rely also on direct mails to their clients. Online marketing often uses direct mail for persuasion of their customers hence the last option is also wrong. Considering that already two statements are identified as inaccurate, the option that "All answer choices are accurate statements about direct-mail messages. " is misleading. Therefore, the only most accurate choice about direct-mail is option A

4 0
4 years ago
Other questions:
  • Tech distractions do NOT include _________.
    9·1 answer
  • A generator that produces 40 kilowatts uses twice as much fuel in an hour as a generator that produces 20 kilowatts. Explain why
    6·1 answer
  • Ice dams are most directly related to:
    5·1 answer
  • When considering free energy change, biochemists usually define a standard state, the biochemical standard state, which is modif
    13·1 answer
  • A thin metal disk of mass m=2.00 x 10^-3 kg and radius R=2.20cm is attached at its center to a long fiber. When the disk is turn
    11·1 answer
  • A pump is used to circulate hot water in a home heating system. Water enters the well-insulated pump operating at steady state a
    14·1 answer
  • In Lab 7, we worked through a program that displayed the homeless shelter occupancy over time. The same approach can be used for
    14·1 answer
  • Which of the following are made up of electrical probes and connectors?
    8·1 answer
  • Please help
    6·1 answer
  • To ensure that a vehicle crash is inelastic, vehicle safety designers add crumple zones to vehicles. A crumple zone is a part of
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!