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
A 300 mm long steel bar with a square cross section (25 mm per edge) is pulled in tension with a load of 83,051 N , and experien
umka2103 [35]

Answer:

the answer is attached with required units.

Explanation:

5 0
3 years ago
For a given set of input values, a NAND gate produces the opposite output as an OR gate with inverted inputs.A. True
Verdich [7]

Answer:

B.

Explanation:

For a given set of input values, A NAND gate produces exactly the same values as an OR gate with inverted inputs.

The truth table  for a NAND gate with 2 inputs is as follows:

0 0    1

0 1     1

1  0    1

1  1    0

The  truth table for an OR gate, is as follows:

0 0    0

0 1     1

1  0    1

1  1     1

If we add two extra columns for inverted inputs, the truth table will be this one:

0 0    1  1       1

0 1     1  0      1

1  0    0  1      1

1  1     0  0     0

which is the same as for the NAND gate, not the opposite, so the statement is false.

This means that the right choice is B.

3 0
3 years ago
Which system provides an easier way for people to communicate with a computer than a graphical user interface (GUI)?
Fed [463]

Answer:

C.

Explanation:

Natural language processing or NLP can be defined as an artificial intelligence that aids computers to understand, interpret, and manipulate human language. NLP is subfiled of many disciplines, for instance, artifical intelligence, linguistics, computer science, etc. NLP helps computers to interact with humans in their own language.

So, the easier way through which people can communicate with computers apart from GUI is NLP. Thus option C is correct.

7 0
3 years ago
How can statistical analysis of a dataset inform a design process
Shtirlitz [24]

Answer:

Explanation:.

3 0
3 years ago
How to make text take shape of object in affinity designer
Alina [70]

Answer:

To fit text to a shape in Affinity Designer, make sure you have your text selected. Then, grab the Frame Text Tool and click on the shape. A blinking cursor will appear within the shape, indicating that you can begin typing. The text you type will be confined to the boundaries of the shape.

Explanation:

6 0
3 years ago
Other questions:
  • If you are sampling a 50Hz signal, what is the minimum sampling rate necessary to prevent aliasing?Why?
    7·1 answer
  • Draw the hierarchy chart and then plan the logic for a program needed by Hometown Bank. The program determines a monthly checkin
    8·1 answer
  • A hollow steel tube with an inside diameter of 100 mm must carry a tensile load of 400 kN. Determine the outside diameter of the
    12·2 answers
  • Can you carry 1 m3 of liquid water? Why or why not? (provide the weight to support your answer)
    7·1 answer
  • The information on a can of pop indicates that the can contains 360 mL. The mass of a full can of pop is 0.369 kg, while an empt
    14·1 answer
  • Describe three parts of a fluid power system and the roles played by each to make the device work.
    8·1 answer
  • Sam, a carpenter, is asked to identify the abilities he has that are important to his work. What are the top abilities he might
    9·2 answers
  • Home safety and security is an _________<br><br> process. (7 Letters)<br><br> Answer
    10·1 answer
  • I really need a good grade please help
    13·1 answer
  • What is the difference between absorbed wavelengths and reflected wavelengths?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!