Danny organized a farewell party for his seniors. He invited N guests. To make the party more enjoyable, he proposes the following game and he offers few cookies as a winning prize
Game rules:
• All the players will sit in a circle. A player with the smallest id(ids always start from 1, incremented by 1) will get the ball and he/she will pick a random number K at the beginning of the gam
• In the clockwise direction, every person has to pass the ball to a player who is at K steps away from the current player holding the ball.
• This will continue until the ball comes back to starting player. when the first player gets the ball back the game ends and players who didn't get the ball will be eliminated.
• Available cookies are equally distributed to all the players who are not eliminated. Next round is played with a different K value
Write a program that accepts the number of players N and the random number picked K for the round and print the ids of the players who are eliminated, in the ascending order Print O if non of the
plavers are eliminated
Read the input from STDIN and write the output to STDOUT. You should not write arbitrary strings while reading the input and while printing as these contribute to the standard output.
1. 1<N<2000, K< N.
if. Every test case has a solution
Input Format:
Single line of input contains N and K. where N is the number of guests and K step to be followed during the game. N and K are separated by a single white space
Output Format:
A single line of output contains single or multiple eliminated persons, each separated by a single white space in ascending order.
10 2
2 4 6 8 10
Here, N = 10 and K =2 So the list will be 1, 3, 5, 7, 9
So the eliminated person are 2, 4, 6, 8, 10.
Sample Input 2:
10 3
0
Explanations:
Here, N = 10 and K=3 So the list will be 1, 4, 7, 10, 3, 6, 9, 2, 5, 8, 1
There are no eliminated persons, so the result is 0.
Raman is a farmer. He wants to buy some pipes of distinct sizes.
some number nums in the form of a bar code. Can you
There were N pipes in the shop and some of them are of the same size. The size of th
write a program that scans all the
bar code and print the number of pipes Raman can get from that shop
Read the input from STDIN and write the output to STDOUT. You should not write arbitrary strings while
Constraints:
reading the input and while printing as these contribute to the standard output
0 <= nums. length <= 3 * 104
-104 <= nums[i] <= 104
nums is sorted in ascending order.
Input Format:
The frst line of input contains N.
The second line of input contains…N pipes separated by a single whie space in ascending order. in
Output Format:
The first line of output contains number of pipes
after scanning all the bar codes.
The second line of output contains pipe sizes after scanning.
Sample Input 1:
3
1 1 2
Sample Output1:
2
1 2
Explanation.
From the sample input1, the given number of pipes 3 and the pipe series are 1,1, and 2.
scanning all the bar codes the first pipe bar code and second pipe bar codes are same. So removing one of them Raman got the two popes of size 1 and size 2
10
0 0 1 1 1 2 2 3 3 4
5
0 1 2 3 4
After scanning,Raman got 5 pipes of sizes 0, 1, 2, 3 and 4.
Question 2
Overview
Solution
Set<int>S
.O(N)
.Pseudo Code
int main(){
take input of elements
loop i to N
insert element in Set
print all the elements in Set
}
Question 1:
Approach
Pseudo Code
int main() {
make boolean array of size N+1 with all true
start = 1
while (start+step)%N != 1
array[(start+step)%N] = false
start = (start+step)%N
all_false = true
for i in 1 to N
if array[i] is true
print i
all_false = false
if all_false
print 0
}