Seedr.cc is the best torrent Stream site free service I had ever seen. I used a lot of sites before, also paid sites, but I had never seen like this site and it’s amazing services before. Seedr allows to you to download torrents very quickly, sometimes you don’t have to wait, because when I add torrent link, I found it’s already there :) and ready for downloading it in very high speed. It also makes you streaming the torrent videos without the need of downloading. And it’s surprised me when I didn’t have to pay for it, because it’s gives you a lot of offers to get more free space. The site gives you 2 GB limit after registration. By inviting 8 friends you got 500 MB for each one, and there a lot of others methods to increase you space, and it’s totally free. I highly recommended this amazing site, you’ll never find site like this in the whole internet. Click to my invite link, and you’ll get 500 Mb more space to be 2.5 GB as total starting space: https://www.seedr.cc/?r=151880
Monday, 19 August 2019
Monday, 17 April 2017
HACKEREARTH: Permutation Swaps
Link:- https://www.hackerearth.com/practice/algorithms/graphs/breadth-first-search/practice-problems/algorithm/permutation-swaps/
Summary:
Given P and Q be two permutation of numbers 1 to N. Given some pair of indexes (ai , bi).
Your task is to find Q from P by swapping (Pai , Pbi).
Print YES if it possible else print NO.
For Example:
Input:
2
4 1
1 3 2 4
1 4 2 3
3 4
4 1
1 3 2 4
1 4 2 3
2 4
Output:
NO
YES
Logic:
Use Breadth First Search(BFS) to find connected components of indexes.
Then check for indexes in each connected component if P and Q are same or not.
To View My Solution:
https://github.com/shivam04/codes/blob/master/hackerearth/algo/graph/medium/permutation-swaps.cpp
Summary:
Given P and Q be two permutation of numbers 1 to N. Given some pair of indexes (ai , bi).
Your task is to find Q from P by swapping (Pai , Pbi).
Print YES if it possible else print NO.
For Example:
Input:
2
4 1
1 3 2 4
1 4 2 3
3 4
4 1
1 3 2 4
1 4 2 3
2 4
Output:
NO
YES
Logic:
Use Breadth First Search(BFS) to find connected components of indexes.
Then check for indexes in each connected component if P and Q are same or not.
To View My Solution:
https://github.com/shivam04/codes/blob/master/hackerearth/algo/graph/medium/permutation-swaps.cpp
Friday, 14 April 2017
HACKEREARTH: Connected Horses
Link:- https://www.hackerearth.com/practice/algorithms/graphs/breadth-first-search/practice-problems/algorithm/connected-horses-10/description/
Summary:
Given N ,M number of rows and columns in a chess board
Given Q queries each query contain co-ordinates of horses in a chess board.
Find the number of ways horses swap their position
For Example:
Sample Input:
2
4 4 4
1 1
1 2
3 1
3 2
4 4 4
1 1
1 2
3 1
4 4
Sample Output:
4
2
Topic:
Breadth First Search(BFS) , Dynamic Programming(DP)
Logic:
Use Breadth First Search(BFS) to find the total number of horses in each connected groups, then find the factorial of this number. Apply same in each group and multiplication of all gives the result. Use DP for calculation of factorials.
To View my solution:
https://github.com/shivam04/codes/blob/master/hackerearth/algo/graph/medium/connected-horses.cpp
Summary:
Given N ,M number of rows and columns in a chess board
Given Q queries each query contain co-ordinates of horses in a chess board.
Find the number of ways horses swap their position
For Example:
Sample Input:
2
4 4 4
1 1
1 2
3 1
3 2
4 4 4
1 1
1 2
3 1
4 4
Sample Output:
4
2
Topic:
Breadth First Search(BFS) , Dynamic Programming(DP)
Logic:
Use Breadth First Search(BFS) to find the total number of horses in each connected groups, then find the factorial of this number. Apply same in each group and multiplication of all gives the result. Use DP for calculation of factorials.
To View my solution:
https://github.com/shivam04/codes/blob/master/hackerearth/algo/graph/medium/connected-horses.cpp
Monday, 12 December 2016
HACKERRANK: Power Of Large Numbers
Link:- https://www.hackerrank.com/challenges/power-of-large-numbers
Summary:
Given A and B.
Find (A^B)%(10^9+7)
Constraints:
1 <= T <= 10
1 <= A,B <= 10100000
A % (109 + 7) != 0
For Example:
Sample Input:
4
3 2
4 5
7 4
34534985349875439875439875349875 93475349759384754395743975349573495
Sample Output:
9
1024
2401
735851262
Logic:
(A^B)%MOD = (A%MOD)^B
Since A is very very large number can't be stored in int or long so using modulo technique bring A in the range of int or long as:
Let 'a' be an array contains digit of A so to construct A%MOD. Let A = 0
for i 0 to len(a):
A = (A*10 + a[i])%MOD
This gives A%MOD
Now B is also very very large but we can't apply same technique as we done in A as
(A%MOD)^B%MOD != (A%MOD)^(B%MOD)%MOD
So we use Fermet's Little Theorem which says:

where p is prime number.
divide by a both side

Since MOD = 10^9+7 is a prime number
we need to find A^B%MOD
so if B is divisible by (p-1) or (MOD-1) then B = (MOD-1)*x
so (A^((MOD-1)*x))%MOD = (A^(MOD-1)%MOD)^x%MOD = 1^x%MOD = 1
and if B is not divisible by (MOD-1) then B = (MOD-1)*x + y
so
(A^((MOD-1)*x+y))%MOD = ((A^(MOD-1)%MOD)^x)%MOD*(a^y)%MOD = 1^x*(a^y)%MOD
and y = B%(MOD-1)
so y can be computed as:
y = 0
b is an array contains digit of number B.
for i 0 to len(b)
y = (y*10 + b[i])%(MOD-1)
if y==0
answer = 1
else
answer = A^y%MOD
To View My Solution:
https://github.com/shivam04/codes/blob/master/hackerrank/math/number%20theory/medium/power-of-large-number.py
Summary:
Given A and B.
Find (A^B)%(10^9+7)
Constraints:
1 <= T <= 10
1 <= A,B <= 10100000
A % (109 + 7) != 0
For Example:
Sample Input:
4
3 2
4 5
7 4
34534985349875439875439875349875 93475349759384754395743975349573495
Sample Output:
9
1024
2401
735851262
Logic:
(A^B)%MOD = (A%MOD)^B
Since A is very very large number can't be stored in int or long so using modulo technique bring A in the range of int or long as:
Let 'a' be an array contains digit of A so to construct A%MOD. Let A = 0
for i 0 to len(a):
A = (A*10 + a[i])%MOD
This gives A%MOD
Now B is also very very large but we can't apply same technique as we done in A as
(A%MOD)^B%MOD != (A%MOD)^(B%MOD)%MOD
So we use Fermet's Little Theorem which says:
where p is prime number.
divide by a both side
Since MOD = 10^9+7 is a prime number
we need to find A^B%MOD
so if B is divisible by (p-1) or (MOD-1) then B = (MOD-1)*x
so (A^((MOD-1)*x))%MOD = (A^(MOD-1)%MOD)^x%MOD = 1^x%MOD = 1
and if B is not divisible by (MOD-1) then B = (MOD-1)*x + y
so
(A^((MOD-1)*x+y))%MOD = ((A^(MOD-1)%MOD)^x)%MOD*(a^y)%MOD = 1^x*(a^y)%MOD
and y = B%(MOD-1)
so y can be computed as:
y = 0
b is an array contains digit of number B.
for i 0 to len(b)
y = (y*10 + b[i])%(MOD-1)
if y==0
answer = 1
else
answer = A^y%MOD
To View My Solution:
https://github.com/shivam04/codes/blob/master/hackerrank/math/number%20theory/medium/power-of-large-number.py
CODEFORCES: Sereja and Suffixes(368B)
Problem Link: http://codeforces.com/problemset/problem/368/B
Summary:
Given 'n' number of elements in array.
Summary:
Given 'n' number of elements in array.
Given 'm' i.e 'm' different queries each query contains an integer 'l'.
Find the number of distinct elements from 'l' to 'n' in array.
For Example:
input
10 10 1 2 3 4 1 2 3 4 100000 99999 1 2 3 4 5 6 7 8 9 10
output
6 6 6 6 6 5 4 3 2 1
Topic:
Dynamic Programming
Logic:
Dynamic Programming
Logic:
Let dp[i] be the answer i.e number of distinct elements from i to n.
and dp[i] = dp[i+1] +1 when element at a[i] has not been visited yet or visit[a[i]] = 0 otherwise dp[i] = dp[i+1] i.e visit[a[i]] = 1
For any 'l' print dp[l] is the answer.
To View my solution:
Thursday, 8 December 2016
HACKER RANK: Journey to the Moon
Problem Link: https://www.hackerrank.com/challenges/journey-to-the-moon
Summary:
Summary:
There are trained astronauts numbered from to . But those in charge of the mission did not receive information about the citizenship of each astronaut. The only information they have is that some particular pairs of astronauts belong to the same country.
Your task is to compute in how many ways they can pick a pair of astronauts belonging to different countries. Assume that you are provided enough pairs to let you identify the groups of astronauts even though you might not know their country directly. For instance, if are astronauts from the same country; it is sufficient to mention that and are pairs of astronauts from the same country without providing information about a third pair .
Print An integer that denotes the number of permissible ways to choose a pair of astronauts.
For Example:
Sample Input:
4 2
0 1
2 3
0 1
2 3
Sample Output:
4
Topic:
Topic:
Graph Theory, BFS(Breadth First Search)
Logic:
I have create an adjacency list.
Then Using BFS I have count total number of sub graphs in a graph such that there is no edges between sub graphs and also count total number of nodes in each sub graph.
Then compute number of ways 2 astronauts from different country can be sent to Moon.
For example:
Like From America There are 3 trained astronauts.
From India There are 4 trained astronauts.
From Japan There are 2 trained astronauts.
From China, Australia and Russia There are Only One astronaut.
So number_of_ways = 3*(4+2+1+1+1) + 4*(2+1+1+1) + 2*(1+1+1) + 2 + 1 = 56
Sunday, 23 October 2016
HACKER RANK: Play Game
Problem Link: https://www.hackerrank.com/challenges/play-game
Summary:
Given N number of elements in stack.
Summary:
Given N number of elements in stack.
first line will contain a number N i.e. number of elements in the stack and next line will contain N numbers i.e. numbers etched on bricks from top to bottom.
You and your friend decide to play a game using a stack consisting of N bricks. In this game, you can alternatively remove 1, 2 or 3 bricks from the top, and the numbers etched on the removed bricks are added to your score. You have to play so that you obtain the maximum possible score. It is given that your friend will also play optimally and you make the first move.
Print a single line containing your maximum score.
For Example:
Sample Input:
2
5
999 1 1 1 0
5
0 1 1 1 999
Sample Output:
1001
999
Logic:
I took dp[2][n]
dp[0]->My Score
dp[1]->Minimum Score other player leaves for me as he also play optimally
When n = 1,2,3 then you took all elements in stack
dp[0][n-1]=a[n-1]
dp[0][n-2]=a[n-1]+a[n-2]
dp[0][n-3]=a[n-1]+a[n-2]+a[n-3]
so for i n-4 to 0:
dp[1][i] = min(dp[0][i+1],min(dp[0][i+2],dp[0][i+3]))
dp[0][i] = max(a[i]+dp[1][i+1],max(a[i]+a[i+1]+dp[1][i+2],a[i]+a[i+1]+a[i+2]+dp[1][i+3]))
ans = dp[0][0]
print ans
In this code dp[1][i] is minimum left by other player for you when he plays optimally i.e chooses maximum sum of elements for itself.
and dp[0][i] is maximum of taking one element, two element or three element plus minimum left by other player when he chooses maximum sum of elements for itself.
Time Complexity: O(n)
To View My Solution:
Subscribe to:
Posts (Atom)