Question: HSBC, Recently Asked Questions for On-Campus Assessment in IIT-K on 30th October
0
Entering edit mode

Question 1

HSBC1.1HSBC1.2

 

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.


Constraints:


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.


Sample Input 1:


10 2


Sample Output 1:


2 4 6 8 10

 

Explanations:

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

 

Sample Output2:

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.

 

Question 2

 

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

 

Sample Input2:


10
0 0 1 1 1 2 2 3 3 4


Output:


5
0 1 2 3 4


Explanation:


After scanning,Raman got 5 pipes of sizes 0, 1, 2, 3 and 4.

 

Click here to Practice

HSBC2.1HSBC2.2

ADD COMMENTlink 2.1 years ago Rohit • 610
0
Entering edit mode

Question 2

Overview

  • The question is nothing but simply finding all the distinct sizes and printing the number of distinct element sizes and printing all such elements in ascending

Solution

  • We can traverse the items one by one and keep inserting all the elements in the Set&lt;int&gt;S.
  • After that, we can simply print the size of the set and print all the elements one by one.
  • We don't worry about the order because in Set elements are sorted by default .
  • Time Complexity: O(N).

Pseudo Code

int main(){
    take input of elements
    loop i to N 
       insert element in Set
    print all the elements in Set 
}
ADD COMMENTlink 2.1 years ago Akshay Sharma 990
0
Entering edit mode

Question 1:

Approach

  • We can keep a boolean array all set to true.
  • Start traversing in the number of steps and set the step index to false
  • End when 1 is reached
  • print all index that are having value as true

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 
}
ADD COMMENTlink 2.1 years ago Tayal • 40

Login before adding your answer.

Similar Posts
Loading Similar Posts