Welcome to My New Technology Blog

Featured
Scala vs Python
List some of the advantages of using Scala, as opposed to other languages. In order to explain this, I am comparing Scala vs Python. If you want to write some serious Apache Spark programming it is better to choose Scala because of following reasons. Note: Following comparisons are based on the fact that I am… Read more

Certifications

Euclidean vs Manhattan Distance
Euclidean Distance: In order to calculate the distance b/w tow points in a given Space – can be a Ndimensional, we can use Euclidean distance formula: D(x1,x2) = SQRT((x1x2)**2 + (y1y2)**2) where SQRT is Square Root D stands for distance b/w point x1,x2. we can extend this for N dimensional plan as follows D(x1,x2,x3,…xn) =… Read more
Follow My Blog
Get new content delivered directly to your inbox.
Python coding
Rearrange a number list such that positive numbers will fit at the end of the list; negative numbers at the beginning of the list:
O(n): T(N) as we are doing inplace and traversing the list only once.
def rearrange(lst):
#assume that left most element is a positive element
leftMostPostiveElementIndex = 0
for curr in range(len(lst)):
if (lst[curr] < 0):
if (curr is not leftMostPostiveElementIndex):
#swamp two
lst[curr], lst[leftMostPostiveElementIndex] = lst[leftMostPostiveElementIndex], lst[curr]
leftMostPostiveElementIndex +=1
return lst
print(rearrange([10,1,20,4,5,9,6]))