Refer: https://en.wikipedia.org/wiki/Introduction_to_Algorithms
C code Refer: https://onlinegdb.com/BJEcW1R34
Python Code Refer: https://onlinegdb.com/S1-U71ChN