A Sum of Coins
You have N coins whose amount ranges from 0 to N-1 respectively. Your friends wants to take K coins out of your coins. You can only give the coins if the set of K coins is useful. A set of coins is useful if the sum of the coins is divisible by a given integer M. Task Determine the number of ways in which your friend can get K coins. Since the answer can be large, print the answer module 10^9 + 7.
You can take coins 0, 1, and 2. All are divisible by M = 1. Therefore the answer is 3.
Complete the solve function provided in the editor. This function takes the following 3 parameters and returns the answer:
- k: Represents the amount of coin your friend wants
- m: Represents the Integer value
- n: Represents the number of coins
Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).
- The first line contains 3 space separated Integers N, K, and M.
Print the answer.
1 <= N <= 10^3
1 <= K <= 10^2
1 <= M <= 10^3
Code snippets (also called starter code/boilerplate code)
This question has code snippets for C, CPP, Java, and Python.
4 2 2
There are 2 ways :
Minimize Path Value
Given a graph G with N nodes and M edges (edges are bi-directional). Every node is assigned a value A[i]. We define a value of path as :
A path consists of a sequence of nodes starting with start node S and end node E.
S -> u1 -> ..... -> E where u1, u2, ... are nodes in G.
Value of path = Maximum of (absolute difference between values of adjacent nodes in Path).
Given a start node S and end node E, find the minimum possible "value of path" which starts with node S and ends with node E.
If N = 5, M = 6, S = 1, E = 4 and A = [3,12,4,7,13].
There are 4 simple paths from node 1 to node 4.
- 1 - 2 - 4: Value of path = Max(12 - 3, 12 - 7) = 9
- 1 - 3 - 4: Value of path = Max(4 - 3, 7 - 4) = 3
- 1 - 3 - 5 - 2 - 4: Value of path = 9 (because of edge 3 - 5)
- 1 - 2 - 5 - 3 - 4: Value of path = 9 (because of edge 3 - 5)
Hence, the minimum possible value of the path is 3.
Complete the pathValue function provided in the editor. This function takes the following 6 parameters and returns minimum possible value of path.
- N : Represents the number of nodes in graph G.
- M : Represents the number of edges in graph G.
- S : Represents the number of nodes in graph G.
- E : Represents the end node of path.
- edge : Represents the edges present in graph G.
- A : Represents the value of nodes in graph G.
- First line contains two space-separated integers N M
- Second line contains two space-separated integers S E
- Next M lines contain two space-separated integers u v, denoting an edge between node u and v
- Next line contains N space-separated integers denoting values of nodes.
1 <= N <= 10^5
N - 1 <= M <= 10^6
1 <= A[i] <= 10^6
Minimum possible "value of path" between node S and E
Use fast I/O.
20 23 21 45 21
Path : 2 -> 3 -> 1 -> 5 will give the minimum possible path value = 2.
Remember there can be multiple paths that give the same minimum path value.