Skip to content

Commit bb88df4

Browse files
authored
Merge pull request ashutosh97#20 from Casey-McCray/master
Arrangement of Queue
2 parents 2495acb + d631cb2 commit bb88df4

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

Arrangement_of_Queue/Question.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Find the arrangement of queue at given time:
2+
3+
n people are standing in a queue to buy entry ticket for the carnival. People present there strongly believe in chivalry. Therefore, at time = t, if a man at position x, finds a woman standing behind him then he exchanges his position with her and therefore, at time = t+1, woman is standing at position x while man is standing behind her.
4+
Given the total number of people standing in a queue as n, particular instant of time as t and the initial arrangement of the queue in the form of a string containing �M� representing man at position i and �W� representing woman is at position i, find out the arrangement of the queue at time = t.

Arrangement_of_Queue/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
### One of the easy Competitve Programming Problems
2+
but still a great add

Arrangement_of_Queue/Solution.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
def solve(n, t, p) :
3+
4+
s = list(p)
5+
6+
for i in range(0, t) :
7+
8+
for j in range(0, n - 1) :
9+
10+
if (s[j] == 'B' and
11+
s[j + 1] == 'G') :
12+
13+
temp = s[j];
14+
s[j] = s[j + 1];
15+
s[j + 1] = temp;
16+
j = j + 1
17+
18+
print (''.join(s))
19+
20+
21+
n = 6
22+
t = 2
23+
p = "BBGBBG"
24+
solve(n, t, p)

0 commit comments

Comments
 (0)