-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_pattern.txt
More file actions
55 lines (39 loc) · 1.76 KB
/
string_pattern.txt
File metadata and controls
55 lines (39 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
length = len(alphabet) -1
output = []
inputstring = "Vrphwklqj phdqlqjixo"
for i in range(len(inputstring)):
if inputstring[i].isalpha():
index = alphabet.index(inputstring[i].lower())
if index >= length-2:
index = index - length - 1
output.append(alphabet[index - 3])
else:
output.append(inputstring[i])
print ''.join(output)
--------------------------------------------------------------------------------------------------------------------------------------
#write a program (in python, javascript or ruby) to populate and then sort a randomly distributed list of 1 million integers, each
integer having a value >= 1 and <= 100 without using any builtin/external library/function for sorting.your program should carefully
consider the input and come up with the most efficient sorting solution you can think of. provide the space and time complexity of
your algorithm
import random
numbers = [random.randint(1,100) for x in xrange(1000000)]
n = len(numbers)
def partition(arr,low,high):
i = ( low-1 ) # index of smaller element
pivot = arr[high] # pivot
for j in range(low , high):
if arr[j] <= pivot:
i = i+1
arr[i],arr[j] = arr[j],arr[i]
arr[i+1],arr[high] = arr[high],arr[i+1]
return ( i+1 )
def quickSort(arr,low,high):
if low < high:
pi = partition(arr,low,high)
quickSort(arr, low, pi-1)
quickSort(arr, pi+1, high)
quickSort(numbers,0,n-1)
print ("Sorted array is:")
for i in range(n):
print ("%d" %numbers[i])