6 kyu

Pile of towels

508 of 957diggi55

Description:

The Situation

In my bathroom, there is a pile of n towels. A towel either has the color red or blue. We will represent the pile as sequence of red and blue.The leftmost towel is at the bottom of the pile, the rightmost towel is at the top of the pile.

As the week goes by, I use t towels. Whenever I grab a new one it's always the towel at the top of the pile. All used towels are placed in a basket.

At the end of the week, I wash all used towels in the basket and put them on top of the existing pile again. But my favorite color is blue, so I want to use blue towels as often as possible. Therefore, when the washed towels are placed on the pile again, the blue towels are always on top of the red towels.

An Example

If there are n=5 towels, a pile may be:blue, red, blue, red, blue

If I grab t=3 towels during the week, this will be the remaining pile at the end of the week: blue, red

The basket will contain the following towels: blue, red, blue

After I sorted the washed towels and put them on the pile according to the rule described above, the resulting pile is:blue, red, red, blue, blue

Your Task: Sort the Pile

You are given an initial pile of towels as a sequence of the strings "red" and "blue". On top of that, you receive a sequence of non-negative integers. The first integer describes the number of used towels t in the first week, the second integer describes the number of used towels t in the second week and so forth.

My question is: How will my pile of towels look like in the end, if I use t towels every week and place them on top of the the pile according to the rule defined above?

Notes

It is ensured that 0 <= t <= n

Sorting
Algorithms

Stats:

CreatedJul 30, 2021
PublishedAug 16, 2021
Warriors Trained2013
Total Skips36
Total Code Submissions3521
Total Times Completed957
Python Completions508
JavaScript Completions354
C++ Completions86
C Completions41
Total Stars36
% of votes with a positive feedback rating94% of 168
Total "Very Satisfied" Votes149
Total "Somewhat Satisfied" Votes17
Total "Not Satisfied" Votes2
Total Rank Assessments27
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • diggi55 Avatar
  • B1ts Avatar
  • FArekkusu Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
Ad