This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ////////////////////////////////////////////////// | |
# ------------Youngest Common Ancestor-------------- | |
# ///////////////////////////////////////////////// | |
''' | |
Question: You are given a BST and 2 descendants. | |
Find the yongest common ancestor to the 2 given descendants node. | |
Example : | |
4 | |
/ \ | |
2 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /////////////////////////////////////// | |
# ------------Find the Triplets--------- | |
# ////////////////////////////////////// | |
''' | |
Question : You are given an array of integer values and a interger value (suppose x). | |
You have to return number of triplets found in the given array such that | |
2nd element = 1st element + x | |
3rd element = 2nd element + x | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ////////////////////////////////////////////////////// | |
# ---------- Find Size of clusters of 1 --------------- | |
# ////////////////////////////////////////////////////// | |
''' | |
Question : You are given a 2D array consisting of 0 and 1s. Find the size of all clusters of 1s. | |
Conditions: You have to consider all neighbors | |
other than digonal neighbors | |
example: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /////////////////////////////////////////////// | |
# -----------------Next word--------------------- | |
#/////////////////////////////////////////////// | |
''' | |
Question : You are given a word, you have to find the least greatest | |
word to the given word. If you can not find return None | |
Example : given : 'acdb' | |
output : 'adbc' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# //////////////////////////////////////////////////// | |
# --------Deleting n-th element from last------------- | |
# //////////////////////////////////////////////////// | |
''' | |
Logic : | |
Suppose we have a linked list 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8 -> 9 -> 0 | |
And we were ask to delete 6th element from last, which is '5' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ///////////////////////////////////////////////// | |
# --------------- Poer Set ----------------------- | |
# //////////////////////////////////////////////// | |
''' | |
Logic : | |
Suppose we are given 'abc' | |
Now take an temp array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/////////////////////////////////////////////////////////// | |
#-------------------- Permutation ------------------------- | |
#///////////////////////////////////////////////////////// | |
''' | |
For logic : https://gist.github.com/jatinsharrma/88345fea62cb088dfab149d81ded49b5 | |
''' | |
def permutation(given): | |
if type(given) == type(2): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#///////////////////////////////////////////////////// | |
#---------------Permutations------------------------- | |
#/////////////////////////////////////////////////// | |
''' | |
1st attempt | |
Logic : | |
This is a recursive solution | |
This method will only work with natural numbers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------ | |
#------------Searching Algorithms---------------- | |
#------------------------------------------------ | |
''' | |
Searching Algorithm: | |
1. Linear Search : Iterative and Recursive | |
2. Binary Search : Iterative and Recursive | |
3. Interpretation Search : Iterative |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#--------------------------------------------- | |
#----------No Of Ways To Make Change---------- | |
#--------------------------------------------- | |
''' | |
Recursive solution | |
Logic: | |
Suppose we are given with coins as [$1,$2,$3] and we have to make $5. |