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
You work for a printing company, and you realize that your colleague sent incorrect price quotes to a client. You begin to write
xxTIMURxx [149]

Answer:

The sentence excerpted from the e-mail uses passive voice.  

Given the  purpose of your message, this voice is appropriate.

Explanation:

Because the objective is to remedy the situation a passive voice is great because it emphasizes the action and the object instead of the subject.

We want to emphasize the document and the incorrect information, not our colleague.

4 0
3 years ago
Which of the following uses pressure and flow to transmit power from one location to another?
lord [1]

Answer:

fluid power

Explanation:

fluids commonly used in fluid power are Oil, Water, Air, CO², and Nitrogen gas, fluid power is commonly confused with hydraulic power, which only uses liquids, fluid power uses either liquids or gases

5 0
2 years ago
In javaWrite a program that simulates flipping a coin to make decisions. The input is how many decisions are needed, and the out
Pavel [41]

Answer:

// Program is written in Java Programming Language

// Comments are used for explanatory purpose

import java.util.*;

public class FlipCoin

{

public static void main(String[] args)

{

// Declare Scanner

Scanner input = new Scanner (System.in);

int flips;

// Prompt to enter number of toss or flips

System.out.print("Number of Flips: ");

flips = input.nextInt();

if (flips > 0)

{

HeadsOrTails();

}

}

}

public static String HeadsOrTails(Random rand)

{

// Simulate the coin tosses.

for (int count = 0; count < flips; count++)

{

rand = new Random();

if (rand.nextInt(2) == 0) {

System.out.println("Tails"); }

else {

System.out.println("Heads"); }

rand = 0;

}

}

7 0
3 years ago
If a pilot-operated check valve (POC) does not check flow, you will see a. erratic actuator movement b, no actuator movement c.
Volgvan

If a pilot-operated check valve (POC) does not check flow, you will see a. erratic actuator movement.

<h3>What is a pilot-operated check valve (POC)?</h3>

Pilot operated test valves paintings through permitting loose float from the inlet port via the opening port. Supplying a pilot strain to the pilot port permits float withinside the contrary direction. Air strain on pinnacle of the poppet meeting opens the seal permitting air to float freely.

An actuator fault is a form of failure affecting the machine inputs. Due to strange operation or fabric aging, actuator faults might also additionally arise withinside the machine. An actuator may be represented through additive and/or multiplicative fault.

Read more about the pilot-operated check valve:

brainly.com/question/13001928

#SPJ1

7 0
1 year ago
Consider a flat plate that is 25 mm long, 30 mm wide, and 1 mm thick and a 50 mm long cylinder with the same volume as the plate
Blizzard [7]

Answer:

Average heat transfer =42.448w/m^2k

Nud = 13.45978

Explanation:

See attachment for step by step guide

4 0
3 years ago
Other questions:
  • Sed is a multipurpose tool that combines the work of several filters. sed performs noninteractive operations on a data stream. s
    12·1 answer
  • Question 9.1 from the textbook. Consider the following workload: Process Burst Time Priority Arrival Time P1 50 4 0 P2 20 1 20 P
    7·1 answer
  • Yasir is trying to build an energy-efficient wall and deciding what materials to use. How can he calculate the thermal resistanc
    6·1 answer
  • In the well-insulated trans-Alaska pipeline, the high viscosity of the oil and long distances cause significant pressure drops,
    12·1 answer
  • Your new team is working hard, but they are all less experienced than you and don't complete their tasks as quickly.What would y
    8·1 answer
  • PLS HURRYY!!!<br> Look at the image below
    10·1 answer
  • PLZZZZZ HELP
    7·2 answers
  • Pleaseeee help me with this!!
    10·1 answer
  • A. Briefly describe the microstructural difference between spheroidite and tempered martensite. Explain why tempered martensite
    14·1 answer
  • What are the maximum weights for single, tandem and 5-axle combinations?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!