Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions UnsortedArray/Attendance_Registry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def Attendance_Registry(Entry):
Count=0
CountMax=0
for x in range(0,10):
if not (x==Entry):
Entry.insert(0,x)
print'Welcome'
Count+=1
print(Entry)
for y in Entry:
for z in Entry:
if(y==z):
Updated_Entry=Entry.remove(z)
print'Bye! See you Again'
CountMax+=1
print(Updated_Entry)
print(Entry)
print Count,CountMax

Entry=[20]
Attendance_Registry(Entry)

12 changes: 12 additions & 0 deletions UnsortedArray/Attendance_Registry_re1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
n=input('number')
data=[1,2,3,4,5]
for x in data:
if not(n==x):
data.append(n)
print('yes! you are Inside')

else:
data.pop(n)
print('You are out')
print(data)

15 changes: 15 additions & 0 deletions UnsortedArray/FindValue_After_R_Rotations_Left.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# find the value after the r rotations left

def Value_After_R_Rotations_Left(a,k):
count=0
while(count!=k):
x=a.pop(-1)
count+=1
a.insert(0,x)
count+1
return a,a[Index]

a=[1,2,3,4,5,6,7,8,9]
k=5
Index=3
print(Value_After_R_Rotations_Left(a,k))
16 changes: 16 additions & 0 deletions UnsortedArray/Find_Value_After_R_Rotations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Find the value which will be in index and get after R Rotations to the Right

def Index_R_Rotations_Find_I(a,I,R):
rotation=1
while(rotation<R):
x=a.pop(-1)
a.insert(0,x)
rotation+=1
Value=-1
if(I<len(a)):
Value=a[I]
return Value
a=[1,2,3,4,5,6,7,8,9,10]
I=5
R=5
print(Index_R_Rotations_Find_I(a,I,R))
14 changes: 14 additions & 0 deletions UnsortedArray/Index_After_Rotations_Left.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#third position after index upto array two rotations left

def Third_Position_Array_Two_Rotation(a):
count=0
while(count!=2):
array=a.pop(-1)
a.insert(0,array)
count+=1

count+=1
return a,array
a=[1,2,3,4,5,6,7,8]
print(Third_Position_Array_Two_Rotation(a))

14 changes: 14 additions & 0 deletions UnsortedArray/Index_After_Two_Rotations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#third position after index upto array two rotations

def Third_Position_Array_Two_Rotation(a):
count=0
while(count!=2):
array=a.pop(0)
count+=1
a.append(array)
count+=1
return a,array
a=[1,2,3,4,5,6,7,8]
print(Third_Position_Array_Two_Rotation(a))


15 changes: 15 additions & 0 deletions UnsortedArray/SubsetA_a_adds_gives_X.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#integer array A and a value X, check if there exists a subset of A of size two that adds upto X (Subset sum for a pair).

def Subset_Pair_X(A,a,X):

for x in A:
for y in a:
if(x+y==X):
print x,y
return 0

A=[1,2,3,4,6,7]
a=[1,2,3,4,5]
X=8
print(Subset_Pair_X(A,a,X))

13 changes: 13 additions & 0 deletions UnsortedArray/Two_arrays_Same.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# find the two unsorted array is same if same returns true if not returns false

def Array_Compare(arr1,arr2):
flag=False
if(len(arr1)==len(arr2)):
for x in arr1:
for y in arr2:
if(x==y):
flag=True
return flag
arr1=[1,2,3,4,5,6,7]
arr2=[1,2,3,4,5,6,7]
print(Array_Compare(arr1,arr2))
13 changes: 13 additions & 0 deletions UnsortedArray/array_conatain_perfectsquare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#find the elements of array whether it is perfect or not,if perfect print the perfect no
import math
def perfectsquare_array(a):
count=0
for i in a:
x=math.sqrt(i)
m=round(x)
if(m-x==0):
print(i)
count+=1
return count
a=[1,2,3,4,6,16]
print(perfectsquare_array(a))
14 changes: 14 additions & 0 deletions UnsortedArray/array_contains_x.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#Array Contains X
def indexarray(arr,x):
index=-1
count=0
for i in arr:
if(i==x):
index=count
break
count+=1

return index
arr=[1,2,3,4,5,6,7]
print(indexarray(arr,8))

7 changes: 7 additions & 0 deletions UnsortedArray/array_duplicate_removed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#print the array without duplicates

def array_no_duplicates(arr):
x=set(arr)

arr=[1,1,2,2,3,4,5]
print(array_no_duplicates(arr))
9 changes: 9 additions & 0 deletions UnsortedArray/array_exe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#length of the Array Questions

def lengthofarray(arr):
count=0
for _ in arr:
count+=1
return count
arr=[1,2,3,4,5,6,2,1,3,4]
print(lengthofarray(arr))
7 changes: 7 additions & 0 deletions UnsortedArray/array_input_return_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def array_input_return_output(arr):
b=[]
for x in arr:
b.append(x)
return b
arr=[1,2,3,4,5]
print(array_input_return_output(arr))
10 changes: 10 additions & 0 deletions UnsortedArray/array_largest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#Find the largest array of an integer

def Largest_Array(arr):
Init_Large=arr[0]
for x in arr:
if(x>Init_Large):
Init_Large=x
return Init_Large
arr=[11,20,3,4,0]
print(Largest_Array(arr))
12 changes: 12 additions & 0 deletions UnsortedArray/array_morethan_once.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#array contains more than once
def more_than_once(arr,x):
flag=False
count=0
for i in arr:
if i==x:
count+=1
if count>1:
flag=True
return flag
arr=[5,2,7,3,1]
print(more_than_once(arr,2))
11 changes: 11 additions & 0 deletions UnsortedArray/array_return_evenno.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#return the even no in an array of elements

def evenno_array(arr):
flag=False
for x in arr:
if(x%2==0):
flag=True
print(x)
return flag
arr=[1,3,4,5,5,7,2,10]
print(evenno_array(arr))
7 changes: 7 additions & 0 deletions UnsortedArray/array_return_oddno.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#display the odd numbers in an array
def oddno_array(arr):
for x in arr:
if not(x%2==0):
print(x)
arr=[1,3,4,5,5,7,2,10]
print(oddno_array(arr))
25 changes: 25 additions & 0 deletions UnsortedArray/array_return_primeno.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#return the no of primeno in an array
import math
def IsPrime(n):
flag=True
for i in range(2,n**1/2):
if(n%i==0):
flag=False
break
return flag

def array_contain_prime(arr):
flag=False
for x in arr:
if(IsPrime(x)):
flag=True
print(x)
return flag

arr=[1,2,5,6,7,11,15]
# arr = int(raw_input('Enter how many elements you want: '))
# for i in range(0, arr):
# x = raw_input('Enter the numbers into the array: ')
print(array_contain_prime(arr))


17 changes: 17 additions & 0 deletions UnsortedArray/array_rev_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#print the contents of the array of reverse in order

# def Array_Reverse_Order(arr):
# b=[]
# x=arr[-1]
# y=arr[0]
# for z in range(x,y,-1):
# b.append(z)
# print(b)
# arr=[1,2,3,4,5]
# Array_Reverse_Order(arr)

def reverse(a):
x=a[::-1]
print(x)
a=[1,3,5,6,7,8]
reverse(a)
10 changes: 10 additions & 0 deletions UnsortedArray/array_reverse_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# array reverse order

def reverse_order_array(array):
b=[]
for x in range(array[-1],array[0],-1):
b.append(x)
print(b)

array=[1,2,3,4,5]
reverse_order_array(array)
11 changes: 11 additions & 0 deletions UnsortedArray/array_smallest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#Find the smallest array of an integer

def Smallest_Array(arr):
Init_Small=arr[0]
for x in arr:
if(x<Init_Small):
Init_Small=x

return Init_Small
arr=[11,20,3,4,0]
print(Smallest_Array(arr))
20 changes: 20 additions & 0 deletions UnsortedArray/array_subset_indices_adds_x.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

#42. Given an unsorted integer array A and a value X, check if there exists a subset of A of size two that adds upto X and print the indices of the values that adds upto X.
import math
def subset_return_index(a,b,c):
for x in a:
a.index(x)
for y in b:
if(x+y==c):
b.index(y)
print x,y
return x,y
a=[1,2,3,4,5]
b=[1,2,3]
c=5
subset_return_index(a,b,c)





12 changes: 12 additions & 0 deletions UnsortedArray/counttime_apperars_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# count the no of times appears in the array

def count_no_element_times(array):
count=0
for x in a:
for y in a:
if(x==y):
count+=1
print(y)
return count
a=[1,2,3,4,5,6,1]
count_no_element_times(a)
13 changes: 13 additions & 0 deletions UnsortedArray/countvalues_givenrange.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# return the count of values with falls in a given range

def Count_Values_Falls_Range(a):
flag=False
for x in a:
for y in a:
if not (x==y):
flag=True
return y,flag
a=[1,2,2,1,22,2,3]
print(Count_Values_Falls_Range(a))


9 changes: 9 additions & 0 deletions UnsortedArray/findX.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def findX(arr,x):
flag=False
for a in arr:
if(arr[a]==x):
flag=True
print'x is availble in array'
return flag
arr=[1,2,3,4,4,5,6]
print(findX(arr,8))
22 changes: 22 additions & 0 deletions UnsortedArray/indices_which_adds_x.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#Return the Indices of Values which adds upto x


def Subset_Pair_X(A,a,X):
for x in A:
for y in a:
if(x+y==X):
print x,y
return 0
def subset_adds_return_indices(array1,array2,x):
Count=0
for x in array1:
for y in array2:
if(Subset_Pair_X(array1,array2,x)==True):
Count+=1
print(array1[x],array2[y])
return False
array1=[1,2,3,4,5]
array2=[1,3,5,6]
x=4
subset_adds_return_indices(array1,array2,x)

Loading