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
Find the largest number. The process of finding the maximum value (i.e., the largest of a group of values) is used frequently in
salantis [7]

Answer:

See Explanation

Explanation:

Required

- Pseudocode to determine the largest of 10 numbers

- C# program to determine the largest of 10 numbers

The pseudocode and program makes use of a 1 dimensional array to accept input for the 10 numbers;

The largest of the 10 numbers is then saved in variable Largest and printed afterwards.

Pseudocode (Number lines are used for indentation to illustrate the program flow)

1. Start:

2. Declare Number as 1 dimensional array of 10 integers

3. Initialize: counter = 0

4. Do:

4.1 Display “Enter Number ”+(counter + 1)

4.2 Accept input for Number[counter]

4.3 While counter < 10

5. Initialize: Largest = Number[0]

6. Loop: i = 0 to 10

6.1 if Largest < Number[i] Then

6.2 Largest = Number[i]

6.3 End Loop:

7. Display “The largest input is “+Largest

8. Stop

C# Program (Console)

Comments are used for explanatory purpose

using System;

namespace ConsoleApplication1

{

   class Program

   {

       static void Main(string[] args)

       {

           int[] Number = new int[10];  // Declare array of 10 elements

           //Accept Input

           int counter = 0;

           while(counter<10)

           {

               Console.WriteLine("Enter Number " + (counter + 1)+": ");

               string var = Console.ReadLine();

               Number[counter] = Convert.ToInt32(var);

               counter++;                  

           }

           //Initialize largest to first element of the array

           int Largest = Number[0];

           //Determine Largest

           for(int i=0;i<10;i++)

           {

               if(Largest < Number[i])

               {

                   Largest = Number[i];

               }

           }

           //Print Largest

           Console.WriteLine("The largest input is "+ Largest);

           Console.ReadLine();

       }

   }

}

8 0
3 years ago
Air enters the compressor of a cold air-standard Brayton cycle with regeneration at 100 kPa, 300 K with a mass flow rate of 6 kg
Marta_Voda [28]

Answer:

Check the explanation

Explanation:

Kindly check the attached image below to see the step by step explanation to the question above.

7 0
3 years ago
The design for a new cementless hip implant is to be studied using an instrumented implant and a fixed simulated femur.
OlgaM077 [116]

Answer:

a) the velocity of the implant immediately after impact is 20 m/s

b) the average resistance of the implant is 40000 N

Explanation:

a) The impulse momentum is:

mv1 + ∑Imp(1---->2) = mv2

According the exercise:

v1=0

∑Imp(1---->2) = F(t2-t1)

m=0.2 kg

Replacing:

0+F(t_{2} -t_{1} )=0.2v_{2}

if F=2 kN and t2-t1=2x10^-3 s. Replacing

0+2x10^{-3} (2x10^{-3} )=0.2v_{2} \\v_{2} =\frac{4}{0.2} =20m/s

b) Work and energy in the system is:

T2 - U(2----->3) = T3

where T2 and T3 are the kinetic energy and U(2----->3) is the work.

T_{2} =\frac{1}{2} mv_{2}^{2}  \\T_{3} =0\\U_{2---3} =-F_{res} x

Replacing:

\frac{1}{2} *0.2*20^{2} -F_{res} *0.001=0\\F_{res} =40000N

3 0
3 years ago
A spherical gas container made of steel has a(n) 17-ft outer diameter and a wall thickness of 0.375 in. Knowing that the interna
Arte-miy333 [17]

Answer:

Maximum Normal Stress σ = 8.16 Ksi

Maximum Shearing Stress τ = 4.08 Ksi

Explanation:

Outer diameter of spherical container D = 17 ft

Convert feet to inches D = 17 x 12 in = 204 inches

Wall thickness t = 0.375 in

Internal Pressure P = 60 Psi

Maximum Normal Stress σ = PD / 4t

σ = PD / 4t

σ = (60 psi x 204 in) / (4 x 0.375 in)

σ = 12,240 / 1.5

σ = 8,160 P/in

σ = 8.16 Ksi

Maximum Shearing Stress τ = PD / 8t

τ = PD / 8t

τ = (60 psi x 204 in) / (8 x 0.375 in)

τ = 12,240 / 3

τ = 4,080 P/in

τ = 4.08 Ksi

7 0
3 years ago
Only an outer panel is being replaced. Technician A says that removing the spot welds by drilling through both panels allows the
Angelina_Jolie [31]

Answer:

6e66363636633747747363637737373737337374

5 0
3 years ago
Other questions:
  • The following figures were obtained in a standard tensile test on a specimen of low carbon steel with a circular sectional area:
    9·1 answer
  • The Molybdenum with an atomic radius 0.1363 nm and atomic weight 95.95 has a BCC unit cell structure. Calculate its theoretical
    15·1 answer
  • A parallel plate capacitor has a separation of 2x10 m and free space between the plates. A 10 V battery is connected across the
    9·1 answer
  • List two common units of measurement to describe height
    5·2 answers
  • Consider tests of an unswept wing that spans the wind tunnel and whose airfoil section is NACA 23012. Since the wing model spans
    13·1 answer
  • Hey answr this sajida Yusof
    15·2 answers
  • Which two statements about professional technical jobs in the energy industry are correct?
    15·2 answers
  • A stainless steel ball (=8055 kg/m3, Cp= 480 J/kgK) of diameter D =15 cm is removed from theoven at a uniform temperature of 3
    13·1 answer
  • Which of these is not a type of socket
    6·1 answer
  • Led test lights are used to test circuits that include controllers and computers. True or false
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!