# Codenation Interview Experience | Online Test

Recently, on-campus drive was held for Codenation for Software Development Engineer Intern.

The process was:

1. Online Test

2. Telephonic Interview

3. Skype Interview

Online test for on-campus was held on September 15th 2020. The off-campus coding challenge known as CodeAgon for the hiring of same position is going to be held on 28th of September. So, I just wanted to share questions asked in online test.

There were *three* questions:

__First Question:__

Alice has got a Random Number Generator. The generator generates a random number from **1** to **N**.

Now Alice wants to know the expected number of turns until **K** distinct elements are generated.

Help Alice find this value modulo **10 ^{9}+7**.

__Problem Constraints:__

1<=K<=N<=10^{5}

__Input format:__

Input consists of 2 arguments, **N=A** and **K=B **in this order.

__Output format:__

Return a single integer , the expected value modulo **10 ^{9}+7**.

__Second Question:__

Given a grid **A** of size **N*M**, 2 players are playing a game on it taking alternate turns.

In each turn, a player chooses a subset of elements from any row and replaces each one of them with their proper divisor.

A proper divisor of a number N is any divisor of N, not equal to N.

The player who is unable to move, loses. Determine the winner of the game.

__Problem Constraints:__

- 1<=N, M<=10
^{3} - 1<=A[i][j]<=10
^{6}

__Input format:__

The only line of argument contains the grid **A**.

__Output format:__

Return a single integer, **1** or** 2** , depending upon which player wins.

__Third Question:__

Given a tree of N nodes numbers **0** to **N-1**. Each node have binary value i.e** 0** or **1** denoted by integer array A.

The beauty of a **i ^{th}** node is

**2**. The total beauty of the Tree is sum of beauty of each node.

^{i}*A[i]Aman is superstitious and will accept the tree only its total beauty is **2 ^{N} -1 or 0**.

He asked you to make the tree acceptable but you can only use the following operation.

- In each operation, select any node
**X**and call**flip(X)**.

## Python

`flip(X):` ` ` `for` `(v: ` `0` `to N` `-` `1` `):` ` ` `if` `(` `all` `nodes ` `in` `path ` `from` `X to node v have same value)` ` ` `A[v] ` `=` `1` `-` `A[v]` |

Find the **minimum** number of operation required to make the tree acceptable.

__Problem Constraints:__

- 1<=N<=10
^{5} - 0<=A[i] <=1
- 0<=B[i][0], B[i][1]<=N-1

__Input format:__

First argument is an integer array A of size N denoting the node value.

Second argument is a 2D array B of size (N-1)*2 where i^{th} edge is between B[i][0] and B[i][1] node

__Output format:__

Return an integer denoting the minimum number of operations required.