/Hackerearth-Problems

Soluions to hackerearth problems

Primary LanguagePython

Hackerearth-Problems

Soluions to Following hackerearth problems

1.Little Monk and Swaps
Given a complete binary tree with N nodes and each node have an distinct integer 'ai' attached with it, find the minimum number of swaps you can make to convert the binary tree into binary search tree. In one swap, you can select any two nodes and swap their values.
You will be given the array representation of the binary tree. Root of the tree will be at'a1'. Left child of root will be at 'a2' and right child of root will be at'a3' . Left child of node at array position 'k' will be at 'k*2' and right child of node at array position 'k' will be at'k*2+1'.
hakerearth link:https://www.hackerearth.com/practice/data-structures/trees/binary-search-tree/practice-problems/algorithm/little-monk-and-swaps/description/
2.Shortest Way
Given a pair (1,1), your aim is to get a new pair (a,b) in minimum number of operations.
There are two types of operations you can use:
1.) If the pair is ( x , y ) then change it to ( x+y, y )
2.) If the pair is ( x , y ) then change it to ( x, x+y )
It is guaranteed that a and b are co-prime.
hakerearth link:https://www.hackerearth.com/problem/algorithm/shortest-way/