Skip to content

Instantly share code, notes, and snippets.

@nainav
Last active April 13, 2018 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nainav/f9b2fa3129116a57888766394d0bcedd to your computer and use it in GitHub Desktop.
Save nainav/f9b2fa3129116a57888766394d0bcedd to your computer and use it in GitHub Desktop.
Programs python
"naina":"naani"
print "Find anagram !\n"
def anagram():
str1='naina'
str2='naina'
list1=list(str1)
list2=list(str2)
list1.sort()
list2.sort()
print list1,list2
position=0
matches=True
if len(list1)==len(list2):
while position < len(list1) and matches:
if list1[position] == list2[position]:
position =position +1
else:
matches =False
return matches
return "length is equal "
else:
return "not equal"
print anagram()
# Hello World program in Python
print "Find minimum Number!\n"
def find_min():
list=[3,5,1,4,5,5,1]
min=list[0]
for a in list:
if a < min:
min =a
return a;
res=find_min()
print res
# Python 3 code to find Maximum difference
# between two elements such that larger
# element appears after the smaller number
# The function assumes that there are at
# least two elements in array. The function
# returns a negative value if the array is
# sorted in decreasing order. Returns 0
# if elements are equal
def maxDiff(arr, arr_size):
max_diff = arr[1] - arr[0]
for i in range( 0, arr_size ):
for j in range( i+1, arr_size ):
if(arr[j] - arr[i] > max_diff):
max_diff = arr[j] - arr[i]
return max_diff
# Driver program to test above function
arr = [1, 2, 90, 10, 110]
size = len(arr)
print ("Maximum difference is", maxDiff(arr, size))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment