diff --git a/1.FindLenght/FindLenght.py b/1.FindLenght/FindLenght.py new file mode 100644 index 0000000..ebbf543 --- /dev/null +++ b/1.FindLenght/FindLenght.py @@ -0,0 +1,11 @@ +#To find the lenght of an array using slicing methodogy + +def count(a): + counti = 0 + while(a[counti:]): + counti += 1 + + return counti + +array = [1,5,4,5,9] +print(count(array)) diff --git a/1.FindLenght/__pycache__/FindLenght.cpython-37.pyc b/1.FindLenght/__pycache__/FindLenght.cpython-37.pyc new file mode 100644 index 0000000..a39b338 Binary files /dev/null and b/1.FindLenght/__pycache__/FindLenght.cpython-37.pyc differ diff --git a/1.FindLenght/__pycache__/test_find_lenght.cpython-37-PYTEST.pyc b/1.FindLenght/__pycache__/test_find_lenght.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..44770e8 Binary files /dev/null and b/1.FindLenght/__pycache__/test_find_lenght.cpython-37-PYTEST.pyc differ diff --git a/1.FindLenght/test_find_lenght.py b/1.FindLenght/test_find_lenght.py new file mode 100644 index 0000000..89aff47 --- /dev/null +++ b/1.FindLenght/test_find_lenght.py @@ -0,0 +1,13 @@ +import FindLenght + +def test_AssertTrue(): + assert True + +def test_array_retutn_5(): + #arrange + array = [1,5,2,8,9] + excepted = 5 + #act + actual = FindLenght.count(array) + #assert + assert excepted == actual \ No newline at end of file diff --git a/10.Find_Min/FindLenght.py b/10.Find_Min/FindLenght.py new file mode 100644 index 0000000..d2c9e33 --- /dev/null +++ b/10.Find_Min/FindLenght.py @@ -0,0 +1,11 @@ +#To find the lenght of an array using slicing methodogy + +def count(a): + counti = 0 + while(a[counti:]): + counti += 1 + + return counti + +#array = [1,5,2,8,9] +#print(count(array)) diff --git a/10.Find_Min/__pycache__/FindLenght.cpython-37.pyc b/10.Find_Min/__pycache__/FindLenght.cpython-37.pyc new file mode 100644 index 0000000..3e83f05 Binary files /dev/null and b/10.Find_Min/__pycache__/FindLenght.cpython-37.pyc differ diff --git a/10.Find_Min/__pycache__/Finding_lenght_of_an_array_without_using_len_functin.cpython-37.pyc b/10.Find_Min/__pycache__/Finding_lenght_of_an_array_without_using_len_functin.cpython-37.pyc new file mode 100644 index 0000000..f359191 Binary files /dev/null and b/10.Find_Min/__pycache__/Finding_lenght_of_an_array_without_using_len_functin.cpython-37.pyc differ diff --git a/10.Find_Min/__pycache__/find_max_element_in_an_array.cpython-37.pyc b/10.Find_Min/__pycache__/find_max_element_in_an_array.cpython-37.pyc new file mode 100644 index 0000000..58ef827 Binary files /dev/null and b/10.Find_Min/__pycache__/find_max_element_in_an_array.cpython-37.pyc differ diff --git a/10.Find_Min/__pycache__/find_min.cpython-37.pyc b/10.Find_Min/__pycache__/find_min.cpython-37.pyc new file mode 100644 index 0000000..749380e Binary files /dev/null and b/10.Find_Min/__pycache__/find_min.cpython-37.pyc differ diff --git a/10.Find_Min/__pycache__/find_min_element_in_an_array.cpython-37.pyc b/10.Find_Min/__pycache__/find_min_element_in_an_array.cpython-37.pyc new file mode 100644 index 0000000..e3bebaf Binary files /dev/null and b/10.Find_Min/__pycache__/find_min_element_in_an_array.cpython-37.pyc differ diff --git a/10.Find_Min/__pycache__/test_find_max.cpython-37-PYTEST.pyc b/10.Find_Min/__pycache__/test_find_max.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..ff7eefb Binary files /dev/null and b/10.Find_Min/__pycache__/test_find_max.cpython-37-PYTEST.pyc differ diff --git a/10.Find_Min/__pycache__/test_find_max_element_in_an_array.cpython-37-PYTEST.pyc b/10.Find_Min/__pycache__/test_find_max_element_in_an_array.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..059d4c8 Binary files /dev/null and b/10.Find_Min/__pycache__/test_find_max_element_in_an_array.cpython-37-PYTEST.pyc differ diff --git a/10.Find_Min/__pycache__/test_find_min.cpython-37-PYTEST.pyc b/10.Find_Min/__pycache__/test_find_min.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..9bfc989 Binary files /dev/null and b/10.Find_Min/__pycache__/test_find_min.cpython-37-PYTEST.pyc differ diff --git a/10.Find_Min/find_min.py b/10.Find_Min/find_min.py new file mode 100644 index 0000000..9ad5df8 --- /dev/null +++ b/10.Find_Min/find_min.py @@ -0,0 +1,20 @@ + # To find the min of dictionary values +import FindLenght +def findMin(values): + + values_count = FindLenght.count(values) + one = values[0] + two = values[1] + if (one < two): + min = one + else: + min = two + i = 2 + while(i!=values_count): + if (values[i] two): + max = one + else: + max = two + i = 2 + while(i!=values_count): + if (values[i]>max): + max = values[i] + i += 1 + return max + +#values = [5,2,4,7,3,5] +#print(Max(values)) \ No newline at end of file diff --git a/11.FindMax/__pycache__/FindLenght.cpython-37.pyc b/11.FindMax/__pycache__/FindLenght.cpython-37.pyc new file mode 100644 index 0000000..774c2a7 Binary files /dev/null and b/11.FindMax/__pycache__/FindLenght.cpython-37.pyc differ diff --git a/11.FindMax/__pycache__/Finding_lenght_of_an_array_without_using_len_functin.cpython-37.pyc b/11.FindMax/__pycache__/Finding_lenght_of_an_array_without_using_len_functin.cpython-37.pyc new file mode 100644 index 0000000..f359191 Binary files /dev/null and b/11.FindMax/__pycache__/Finding_lenght_of_an_array_without_using_len_functin.cpython-37.pyc differ diff --git a/11.FindMax/__pycache__/Max.cpython-37.pyc b/11.FindMax/__pycache__/Max.cpython-37.pyc new file mode 100644 index 0000000..4f58351 Binary files /dev/null and b/11.FindMax/__pycache__/Max.cpython-37.pyc differ diff --git a/11.FindMax/__pycache__/find_max_element_in_an_array.cpython-37.pyc b/11.FindMax/__pycache__/find_max_element_in_an_array.cpython-37.pyc new file mode 100644 index 0000000..58ef827 Binary files /dev/null and b/11.FindMax/__pycache__/find_max_element_in_an_array.cpython-37.pyc differ diff --git a/11.FindMax/__pycache__/test_find_max.cpython-37-PYTEST.pyc b/11.FindMax/__pycache__/test_find_max.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..1a9403a Binary files /dev/null and b/11.FindMax/__pycache__/test_find_max.cpython-37-PYTEST.pyc differ diff --git a/11.FindMax/__pycache__/test_find_max_element_in_an_array.cpython-37-PYTEST.pyc b/11.FindMax/__pycache__/test_find_max_element_in_an_array.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..059d4c8 Binary files /dev/null and b/11.FindMax/__pycache__/test_find_max_element_in_an_array.cpython-37-PYTEST.pyc differ diff --git a/11.FindMax/test_find_max.py b/11.FindMax/test_find_max.py new file mode 100644 index 0000000..93c0323 --- /dev/null +++ b/11.FindMax/test_find_max.py @@ -0,0 +1,14 @@ + +import Max + +def test_AssertTrue(): + assert True + +def test_arrayretutn7(): + #arrange + values = [5,2,4,7,3,5] + excepted = 7 + #act + actual = Max.Max(values) + #assert + assert excepted == actual \ No newline at end of file diff --git a/12.Find_largest_number_count_value/FindLenght.py b/12.Find_largest_number_count_value/FindLenght.py new file mode 100644 index 0000000..d2c9e33 --- /dev/null +++ b/12.Find_largest_number_count_value/FindLenght.py @@ -0,0 +1,11 @@ +#To find the lenght of an array using slicing methodogy + +def count(a): + counti = 0 + while(a[counti:]): + counti += 1 + + return counti + +#array = [1,5,2,8,9] +#print(count(array)) diff --git a/12.Find_largest_number_count_value/Max.py b/12.Find_largest_number_count_value/Max.py new file mode 100644 index 0000000..04719a8 --- /dev/null +++ b/12.Find_largest_number_count_value/Max.py @@ -0,0 +1,20 @@ + # To find the max of dictionary values +import FindLenght +def max(values): + + values_count = FindLenght.count(values) + one = values[0] + two = values[1] + if (one > two): + max = one + else: + max = two + i = 2 + while(i!=values_count): + if (values[i]>max): + max = values[i] + i += 1 + return max + +#values = [5,2,4,7,3,5] +#print(find_largest_value(values)) \ No newline at end of file diff --git a/12.Find_largest_number_count_value/__pycache__/FindLenght.cpython-37.pyc b/12.Find_largest_number_count_value/__pycache__/FindLenght.cpython-37.pyc new file mode 100644 index 0000000..5945040 Binary files /dev/null and b/12.Find_largest_number_count_value/__pycache__/FindLenght.cpython-37.pyc differ diff --git a/12.Find_largest_number_count_value/__pycache__/Finding_lenght_of_an_array_without_using_len_functin.cpython-37.pyc b/12.Find_largest_number_count_value/__pycache__/Finding_lenght_of_an_array_without_using_len_functin.cpython-37.pyc new file mode 100644 index 0000000..76be899 Binary files /dev/null and b/12.Find_largest_number_count_value/__pycache__/Finding_lenght_of_an_array_without_using_len_functin.cpython-37.pyc differ diff --git a/12.Find_largest_number_count_value/__pycache__/Max.cpython-37.pyc b/12.Find_largest_number_count_value/__pycache__/Max.cpython-37.pyc new file mode 100644 index 0000000..13ced4b Binary files /dev/null and b/12.Find_largest_number_count_value/__pycache__/Max.cpython-37.pyc differ diff --git a/12.Find_largest_number_count_value/__pycache__/find_largest_number_count.cpython-37.pyc b/12.Find_largest_number_count_value/__pycache__/find_largest_number_count.cpython-37.pyc new file mode 100644 index 0000000..87333a0 Binary files /dev/null and b/12.Find_largest_number_count_value/__pycache__/find_largest_number_count.cpython-37.pyc differ diff --git a/12.Find_largest_number_count_value/__pycache__/find_max_element_in_an_array.cpython-37.pyc b/12.Find_largest_number_count_value/__pycache__/find_max_element_in_an_array.cpython-37.pyc new file mode 100644 index 0000000..46ff007 Binary files /dev/null and b/12.Find_largest_number_count_value/__pycache__/find_max_element_in_an_array.cpython-37.pyc differ diff --git a/12.Find_largest_number_count_value/__pycache__/findthelargestnumberoccurencesinanarray.cpython-37.pyc b/12.Find_largest_number_count_value/__pycache__/findthelargestnumberoccurencesinanarray.cpython-37.pyc new file mode 100644 index 0000000..e6faed7 Binary files /dev/null and b/12.Find_largest_number_count_value/__pycache__/findthelargestnumberoccurencesinanarray.cpython-37.pyc differ diff --git a/12.Find_largest_number_count_value/__pycache__/test_find_occurences_of_max_element.cpython-37-PYTEST.pyc b/12.Find_largest_number_count_value/__pycache__/test_find_occurences_of_max_element.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..72c771e Binary files /dev/null and b/12.Find_largest_number_count_value/__pycache__/test_find_occurences_of_max_element.cpython-37-PYTEST.pyc differ diff --git a/12.Find_largest_number_count_value/__pycache__/test_largest_Number_Count.cpython-37-PYTEST.pyc b/12.Find_largest_number_count_value/__pycache__/test_largest_Number_Count.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..e626f0f Binary files /dev/null and b/12.Find_largest_number_count_value/__pycache__/test_largest_Number_Count.cpython-37-PYTEST.pyc differ diff --git a/12.Find_largest_number_count_value/__pycache__/test_max_numbers_occurences.cpython-37-PYTEST.pyc b/12.Find_largest_number_count_value/__pycache__/test_max_numbers_occurences.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..f31b931 Binary files /dev/null and b/12.Find_largest_number_count_value/__pycache__/test_max_numbers_occurences.cpython-37-PYTEST.pyc differ diff --git a/12.Find_largest_number_count_value/find_largest_number_count.py b/12.Find_largest_number_count_value/find_largest_number_count.py new file mode 100644 index 0000000..f282998 --- /dev/null +++ b/12.Find_largest_number_count_value/find_largest_number_count.py @@ -0,0 +1,20 @@ +#12. Given an unsorted integer array A, +# find the number of times the smallest number is found in the array. +import Max +import FindLenght +def count_occuences(array,max): + count = 0 + i = 0 + lenght = FindLenght.count(array) + while (i!=lenght): + if (array[i]==max): + count += 1 + i += 1 + return count + +def find_largest_numbers_occurences(array): + max = Max.max(array) + count = count_occuences(array,max) + return count +array = [3,9,2,7,9] +print(find_largest_numbers_occurences(array)) diff --git a/12.Find_largest_number_count_value/test_largest_Number_Count.py b/12.Find_largest_number_count_value/test_largest_Number_Count.py new file mode 100644 index 0000000..e352f8a --- /dev/null +++ b/12.Find_largest_number_count_value/test_largest_Number_Count.py @@ -0,0 +1,13 @@ +import find_largest_number_count +def assertTrue(): + assert True + +def arrayreturn2(): + #arrange + array = [3,9,2,7,9] + excepted = 2 + #act + actual = find_largest_number_count.find_largest_numbers_occurences(array) + #assert + assert excepted == actual + \ No newline at end of file diff --git a/13.findSmallnumberCount/FindLenght.py b/13.findSmallnumberCount/FindLenght.py new file mode 100644 index 0000000..d2c9e33 --- /dev/null +++ b/13.findSmallnumberCount/FindLenght.py @@ -0,0 +1,11 @@ +#To find the lenght of an array using slicing methodogy + +def count(a): + counti = 0 + while(a[counti:]): + counti += 1 + + return counti + +#array = [1,5,2,8,9] +#print(count(array)) diff --git a/13.findSmallnumberCount/__pycache__/FindLenght.cpython-37.pyc b/13.findSmallnumberCount/__pycache__/FindLenght.cpython-37.pyc new file mode 100644 index 0000000..5523613 Binary files /dev/null and b/13.findSmallnumberCount/__pycache__/FindLenght.cpython-37.pyc differ diff --git a/13.findSmallnumberCount/__pycache__/Finding_lenght_of_an_array_without_using_len_functin.cpython-37.pyc b/13.findSmallnumberCount/__pycache__/Finding_lenght_of_an_array_without_using_len_functin.cpython-37.pyc new file mode 100644 index 0000000..76be899 Binary files /dev/null and b/13.findSmallnumberCount/__pycache__/Finding_lenght_of_an_array_without_using_len_functin.cpython-37.pyc differ diff --git a/13.findSmallnumberCount/__pycache__/findSmallestNumberCount.cpython-37.pyc b/13.findSmallnumberCount/__pycache__/findSmallestNumberCount.cpython-37.pyc new file mode 100644 index 0000000..8007685 Binary files /dev/null and b/13.findSmallnumberCount/__pycache__/findSmallestNumberCount.cpython-37.pyc differ diff --git a/13.findSmallnumberCount/__pycache__/find_max_element_in_an_array.cpython-37.pyc b/13.findSmallnumberCount/__pycache__/find_max_element_in_an_array.cpython-37.pyc new file mode 100644 index 0000000..46ff007 Binary files /dev/null and b/13.findSmallnumberCount/__pycache__/find_max_element_in_an_array.cpython-37.pyc differ diff --git a/13.findSmallnumberCount/__pycache__/find_min.cpython-37.pyc b/13.findSmallnumberCount/__pycache__/find_min.cpython-37.pyc new file mode 100644 index 0000000..573b83c Binary files /dev/null and b/13.findSmallnumberCount/__pycache__/find_min.cpython-37.pyc differ diff --git a/13.findSmallnumberCount/__pycache__/find_min_element_in_an_array.cpython-37.pyc b/13.findSmallnumberCount/__pycache__/find_min_element_in_an_array.cpython-37.pyc new file mode 100644 index 0000000..6c8eecb Binary files /dev/null and b/13.findSmallnumberCount/__pycache__/find_min_element_in_an_array.cpython-37.pyc differ diff --git a/13.findSmallnumberCount/__pycache__/findthelargestnumberoccurencesinanarray.cpython-37.pyc b/13.findSmallnumberCount/__pycache__/findthelargestnumberoccurencesinanarray.cpython-37.pyc new file mode 100644 index 0000000..e6faed7 Binary files /dev/null and b/13.findSmallnumberCount/__pycache__/findthelargestnumberoccurencesinanarray.cpython-37.pyc differ diff --git a/13.findSmallnumberCount/__pycache__/test_find_min.cpython-37-PYTEST.pyc b/13.findSmallnumberCount/__pycache__/test_find_min.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..85a8d01 Binary files /dev/null and b/13.findSmallnumberCount/__pycache__/test_find_min.cpython-37-PYTEST.pyc differ diff --git a/13.findSmallnumberCount/__pycache__/test_find_occurences_of_max_element.cpython-37-PYTEST.pyc b/13.findSmallnumberCount/__pycache__/test_find_occurences_of_max_element.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..72c771e Binary files /dev/null and b/13.findSmallnumberCount/__pycache__/test_find_occurences_of_max_element.cpython-37-PYTEST.pyc differ diff --git a/13.findSmallnumberCount/__pycache__/test_max_numbers_occurences.cpython-37-PYTEST.pyc b/13.findSmallnumberCount/__pycache__/test_max_numbers_occurences.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..f31b931 Binary files /dev/null and b/13.findSmallnumberCount/__pycache__/test_max_numbers_occurences.cpython-37-PYTEST.pyc differ diff --git a/13.findSmallnumberCount/findSmallestNumberCount.py b/13.findSmallnumberCount/findSmallestNumberCount.py new file mode 100644 index 0000000..ece425b --- /dev/null +++ b/13.findSmallnumberCount/findSmallestNumberCount.py @@ -0,0 +1,20 @@ +#12. Given an unsorted integer array A, +# find the number of times the smallest number is found in the array. +import find_min +import FindLenght +def count_occuences(array,min): + count = 0 + i = 0 + lenght = FindLenght.count(array) + while (i!=lenght): + if (array[i]==min): + count += 1 + i += 1 + return count + +def find_Smallest_numbers_occurences(array): + min = find_min.find_smallest_value(array) + count = count_occuences(array,min) + return count +array = [3,8,3,7,9] +print(find_Smallest_numbers_occurences(array)) diff --git a/13.findSmallnumberCount/find_min.py b/13.findSmallnumberCount/find_min.py new file mode 100644 index 0000000..a2a5f9a --- /dev/null +++ b/13.findSmallnumberCount/find_min.py @@ -0,0 +1,20 @@ + # To find the min of dictionary values +import FindLenght +def find_smallest_value(values): + + values_count = FindLenght.count(values) + one = values[0] + two = values[1] + if (one < two): + min = one + else: + min = two + i = 2 + while(i!=values_count): + if (values[i] two): + max = one + else: + max = two + i = 2 + while(i!=values_count): + if (values[i]>max): + max = values[i] + i += 1 + return max + +#values = [5,2,4,7,3,5] +#print(Max(values)) \ No newline at end of file diff --git a/25.2ndLargestNumber/__pycache__/FindLenght.cpython-37.pyc b/25.2ndLargestNumber/__pycache__/FindLenght.cpython-37.pyc new file mode 100644 index 0000000..14cd792 Binary files /dev/null and b/25.2ndLargestNumber/__pycache__/FindLenght.cpython-37.pyc differ diff --git a/25.2ndLargestNumber/__pycache__/Max.cpython-37.pyc b/25.2ndLargestNumber/__pycache__/Max.cpython-37.pyc new file mode 100644 index 0000000..623f017 Binary files /dev/null and b/25.2ndLargestNumber/__pycache__/Max.cpython-37.pyc differ diff --git a/25.2ndSmallestNumber/2ndSmallestNumber.py b/25.2ndSmallestNumber/2ndSmallestNumber.py new file mode 100644 index 0000000..289f43f --- /dev/null +++ b/25.2ndSmallestNumber/2ndSmallestNumber.py @@ -0,0 +1,13 @@ +import find_min + +def secondsmallestNumber(array): + v = find_min.findMin(array) + for i in array: + if v == i: + array.remove(i) + maxi = find_min.findMin(array) + + return maxi + +array = [3,1,6,9,3] +print(secondsmallestNumber(array)) \ No newline at end of file diff --git a/25.2ndSmallestNumber/FindLenght.py b/25.2ndSmallestNumber/FindLenght.py new file mode 100644 index 0000000..d2c9e33 --- /dev/null +++ b/25.2ndSmallestNumber/FindLenght.py @@ -0,0 +1,11 @@ +#To find the lenght of an array using slicing methodogy + +def count(a): + counti = 0 + while(a[counti:]): + counti += 1 + + return counti + +#array = [1,5,2,8,9] +#print(count(array)) diff --git a/25.2ndSmallestNumber/__pycache__/FindLenght.cpython-37.pyc b/25.2ndSmallestNumber/__pycache__/FindLenght.cpython-37.pyc new file mode 100644 index 0000000..e389794 Binary files /dev/null and b/25.2ndSmallestNumber/__pycache__/FindLenght.cpython-37.pyc differ diff --git a/25.2ndSmallestNumber/__pycache__/find_min.cpython-37.pyc b/25.2ndSmallestNumber/__pycache__/find_min.cpython-37.pyc new file mode 100644 index 0000000..121c131 Binary files /dev/null and b/25.2ndSmallestNumber/__pycache__/find_min.cpython-37.pyc differ diff --git a/25.2ndSmallestNumber/find_min.py b/25.2ndSmallestNumber/find_min.py new file mode 100644 index 0000000..9ad5df8 --- /dev/null +++ b/25.2ndSmallestNumber/find_min.py @@ -0,0 +1,20 @@ + # To find the min of dictionary values +import FindLenght +def findMin(values): + + values_count = FindLenght.count(values) + one = values[0] + two = values[1] + if (one < two): + min = one + else: + min = two + i = 2 + while(i!=values_count): + if (values[i] two): + max = one + else: + max = two + i = 2 + while(i!=values_count): + if (values[i]>max): + max = values[i] + i += 1 + return max + +#values = [5,2,4,7,3,5] +#print(Max(values)) \ No newline at end of file diff --git a/26.Find_kth_Largest_ele/__pycache__/FindLenght.cpython-37.pyc b/26.Find_kth_Largest_ele/__pycache__/FindLenght.cpython-37.pyc new file mode 100644 index 0000000..d9112fa Binary files /dev/null and b/26.Find_kth_Largest_ele/__pycache__/FindLenght.cpython-37.pyc differ diff --git a/26.Find_kth_Largest_ele/__pycache__/Max.cpython-37.pyc b/26.Find_kth_Largest_ele/__pycache__/Max.cpython-37.pyc new file mode 100644 index 0000000..536272f Binary files /dev/null and b/26.Find_kth_Largest_ele/__pycache__/Max.cpython-37.pyc differ diff --git a/26.Find_kth_Largest_ele/__pycache__/find_min.cpython-37.pyc b/26.Find_kth_Largest_ele/__pycache__/find_min.cpython-37.pyc new file mode 100644 index 0000000..989c787 Binary files /dev/null and b/26.Find_kth_Largest_ele/__pycache__/find_min.cpython-37.pyc differ diff --git a/26.Find_kth_Largest_ele/find_kth_Largest_ele.py b/26.Find_kth_Largest_ele/find_kth_Largest_ele.py new file mode 100644 index 0000000..4768b01 --- /dev/null +++ b/26.Find_kth_Largest_ele/find_kth_Largest_ele.py @@ -0,0 +1,24 @@ +import Max +import FindLenght +import find_min +def kth_largest_ele(array,kthele): + lenght = FindLenght.count(array) + if (lenght == kthele): + return find_min.findMin(array) + else: + + iterator = 1 + while(iterator!=kthele): + Largest_ele = Max.Max(array) + for j in array: + if (j == Largest_ele): + array.remove(Largest_ele) + iterator += 1 + Largest_ele = Max.Max(array) + return Largest_ele + +array = [5,1,9,7,2,8,3,6,4] +kthele = 1 +#print() +v = kth_largest_ele(array,kthele) +print("The {0} Largest Element in the array is {1}".format(kthele,v)) \ No newline at end of file diff --git a/26.Find_kth_Largest_ele/find_min.py b/26.Find_kth_Largest_ele/find_min.py new file mode 100644 index 0000000..9ad5df8 --- /dev/null +++ b/26.Find_kth_Largest_ele/find_min.py @@ -0,0 +1,20 @@ + # To find the min of dictionary values +import FindLenght +def findMin(values): + + values_count = FindLenght.count(values) + one = values[0] + two = values[1] + if (one < two): + min = one + else: + min = two + i = 2 + while(i!=values_count): + if (values[i] two): + max = one + else: + max = two + i = 2 + while(i!=values_count): + if (values[i]>max): + max = values[i] + i += 1 + return max + +#values = [5,2,4,7,3,5] +#print(Max(values)) \ No newline at end of file diff --git a/26.Find_kth_smallest_ele/__pycache__/FindLenght.cpython-37.pyc b/26.Find_kth_smallest_ele/__pycache__/FindLenght.cpython-37.pyc new file mode 100644 index 0000000..71f0b3d Binary files /dev/null and b/26.Find_kth_smallest_ele/__pycache__/FindLenght.cpython-37.pyc differ diff --git a/26.Find_kth_smallest_ele/__pycache__/Max.cpython-37.pyc b/26.Find_kth_smallest_ele/__pycache__/Max.cpython-37.pyc new file mode 100644 index 0000000..9cd584d Binary files /dev/null and b/26.Find_kth_smallest_ele/__pycache__/Max.cpython-37.pyc differ diff --git a/26.Find_kth_smallest_ele/__pycache__/find_min.cpython-37.pyc b/26.Find_kth_smallest_ele/__pycache__/find_min.cpython-37.pyc new file mode 100644 index 0000000..ca91950 Binary files /dev/null and b/26.Find_kth_smallest_ele/__pycache__/find_min.cpython-37.pyc differ diff --git a/26.Find_kth_smallest_ele/find_kth_smallest_ele.py b/26.Find_kth_smallest_ele/find_kth_smallest_ele.py new file mode 100644 index 0000000..967013b --- /dev/null +++ b/26.Find_kth_smallest_ele/find_kth_smallest_ele.py @@ -0,0 +1,24 @@ +import find_min +import FindLenght +import Max +def kth_smallest_ele(array,kthele): + smallest_ele = 1 + iterator = 1 + lenght = FindLenght.count(array) + while(iterator!=kthele): + if lenght == kthele : + return Max.Max(array) + else: + smallest_ele = find_min.findMin(array) + for j in array: + if (j == smallest_ele): + array.remove(smallest_ele) + iterator += 1 + smallest_ele = find_min.findMin(array) + return smallest_ele + +array = [5,1,9,7,2,8,3,6,4] +kthele = 9 +#print() +v = kth_smallest_ele(array,kthele) +print("The {0} Smallest Element in the array is {1}".format(kthele,v)) \ No newline at end of file diff --git a/26.Find_kth_smallest_ele/find_min.py b/26.Find_kth_smallest_ele/find_min.py new file mode 100644 index 0000000..9ad5df8 --- /dev/null +++ b/26.Find_kth_smallest_ele/find_min.py @@ -0,0 +1,20 @@ + # To find the min of dictionary values +import FindLenght +def findMin(values): + + values_count = FindLenght.count(values) + one = values[0] + two = values[1] + if (one < two): + min = one + else: + min = two + i = 2 + while(i!=values_count): + if (values[i]= search_ele): + #flag = True + break + + return add +array = [5,1,9,7,2,8,3,6,4] +search_ele = 25 +print(validate(array,search_ele)) + diff --git a/28.Count_upto_greater/FindLenght.py b/28.Count_upto_greater/FindLenght.py new file mode 100644 index 0000000..d2c9e33 --- /dev/null +++ b/28.Count_upto_greater/FindLenght.py @@ -0,0 +1,11 @@ +#To find the lenght of an array using slicing methodogy + +def count(a): + counti = 0 + while(a[counti:]): + counti += 1 + + return counti + +#array = [1,5,2,8,9] +#print(count(array)) diff --git a/28.Count_upto_greater/__pycache__/FindLenght.cpython-37.pyc b/28.Count_upto_greater/__pycache__/FindLenght.cpython-37.pyc new file mode 100644 index 0000000..947aeb8 Binary files /dev/null and b/28.Count_upto_greater/__pycache__/FindLenght.cpython-37.pyc differ diff --git a/28.Count_upto_greater/count_upto_greater.py b/28.Count_upto_greater/count_upto_greater.py new file mode 100644 index 0000000..e203f37 --- /dev/null +++ b/28.Count_upto_greater/count_upto_greater.py @@ -0,0 +1,19 @@ +#28. Given an unsorted integer array and an integer +# value X as input, return the count of the values greater than or equal to X. +import FindLenght +def validate(array,search_ele): + #flag = False + add = array[0] + array[1] + i = 2 + Lenght = FindLenght.count(array) + + while (i!=Lenght): + add = add + array[i] + if (add >= search_ele): + #flag = True + break + + return add +array = [5,1,9,7,2,8,3,6,4] +search_ele = 25 +print(validate(array,search_ele)) \ No newline at end of file diff --git a/29.swap_one_bit_right/swapRight.py b/29.swap_one_bit_right/swapRight.py new file mode 100644 index 0000000..c8300a5 --- /dev/null +++ b/29.swap_one_bit_right/swapRight.py @@ -0,0 +1,16 @@ +def swapRight(array): + + + temp = 0 + j = 0 + while (j!=1): + i = -1 + while (i!=len(array)): + array[i],temp = temp,array[i] + i += 1 + j += 1 + return array + +array = [5,7,6,9,2,8] +print(array) +print(swapRight(array)) \ No newline at end of file diff --git a/3.getIndex/FindLenght.py b/3.getIndex/FindLenght.py new file mode 100644 index 0000000..50ce3fe --- /dev/null +++ b/3.getIndex/FindLenght.py @@ -0,0 +1,11 @@ +#To find the lenght of an array using slicing methodogy + +def count(a): + counti = 0 + while(a[counti:]): + counti += 1 + + return counti + +array = [1,5,2,8,9] +print(count(array)) diff --git a/3.getIndex/__pycache__/FindLenght.cpython-37.pyc b/3.getIndex/__pycache__/FindLenght.cpython-37.pyc new file mode 100644 index 0000000..caa821b Binary files /dev/null and b/3.getIndex/__pycache__/FindLenght.cpython-37.pyc differ diff --git a/3.getIndex/getIndex.py b/3.getIndex/getIndex.py new file mode 100644 index 0000000..0fb72bc --- /dev/null +++ b/3.getIndex/getIndex.py @@ -0,0 +1,17 @@ +#3. Given an unsorted integer array A and an integer value X, +# return the index at which X is located in A or return -1 if it is not found in A. +#import FindLenght +def getIndex(array,indexFor): + index = 0 + i = 0 + lennght = len(array) + while (i!=lennght): + if (array[i] == indexFor): + break + index += 1 + i += 1 + return index + +array = [7,4,5,7] +indexFor = 5 +print(getIndex(array,indexFor)) \ No newline at end of file diff --git a/30.Shiftleft/shiftLeft.py b/30.Shiftleft/shiftLeft.py new file mode 100644 index 0000000..1f86d3c --- /dev/null +++ b/30.Shiftleft/shiftLeft.py @@ -0,0 +1,13 @@ +def shiftLeft(array): + i = 0 + while(i!=1): + j = 0 + temp = (array[j]) + array.remove(array[j]) + array.append(temp) + i+=1 + return array + +array = [5,7,6,9,2,8] +print(array) +print(shiftLeft(array)) \ No newline at end of file diff --git a/31.shiftRightby2bits/shiftRightby2.py b/31.shiftRightby2bits/shiftRightby2.py new file mode 100644 index 0000000..351673f --- /dev/null +++ b/31.shiftRightby2bits/shiftRightby2.py @@ -0,0 +1,19 @@ +#31. Given an unsorted +# integer array as input, rotate the contents of the array to the right by 2 positions. + +def swapRight(array): + + + temp = 0 + j = 0 + while (j!=2): + i = -1 + while (i!=len(array)): + array[i],temp = temp,array[i] + i += 1 + j += 1 + return array + +array = [5,7,6,9,2,8] +print(array) +print(swapRight(array)) \ No newline at end of file diff --git a/32.shiftrightleft/shiftrightleft.py b/32.shiftrightleft/shiftrightleft.py new file mode 100644 index 0000000..a36ad29 --- /dev/null +++ b/32.shiftrightleft/shiftrightleft.py @@ -0,0 +1,30 @@ +def swapRight(array,shiftValue): + temp = 0 + j = 0 + while (j!=shiftValue): + i = -1 + while (i!=len(array)): + array[i],temp = temp,array[i] + i += 1 + j += 1 + return array + +def shiftLeft(array,shiftValue): + i = 0 + while(i!=shiftValue): + j = 0 + temp = (array[j]) + array.remove(array[j]) + array.append(temp) + i+=1 + return array + + +array = [5,7,6,9,2,8] +shiftValue = 5 +print(array) +print("Shift Right") +print(swapRight(array,shiftValue)) +print("Shift Left") +array = [5,7,6,9,2,8] +print(shiftLeft(array,shiftValue)) diff --git a/33.shiftGreaterThanN/shiftGreaterN.py b/33.shiftGreaterThanN/shiftGreaterN.py new file mode 100644 index 0000000..49cf8d3 --- /dev/null +++ b/33.shiftGreaterThanN/shiftGreaterN.py @@ -0,0 +1,35 @@ +def swapRight(array,shiftValue): + if (shiftValue > len(array)): + shiftValue = shiftValue - len(array) + + temp = 0 + j = 0 + while (j!=shiftValue): + i = -1 + while (i!=len(array)): + array[i],temp = temp,array[i] + i += 1 + j += 1 + return array + +def shiftLeft(array,shiftValue): + if (shiftValue > len(array)): + shiftValue = shiftValue - len(array) + i = 0 + while(i!=shiftValue): + j = 0 + temp = (array[j]) + array.remove(array[j]) + array.append(temp) + i+=1 + return array + + +array = [5,7,6,9,2,8] +shiftValue = 10 +print(array) +print("Shift Right") +print(swapRight(array,shiftValue)) +print("Shift Left") +array = [5,7,6,9,2,8] +print(shiftLeft(array,shiftValue)) diff --git a/35.FindUniqueElements/FindLenght.py b/35.FindUniqueElements/FindLenght.py new file mode 100644 index 0000000..d2c9e33 --- /dev/null +++ b/35.FindUniqueElements/FindLenght.py @@ -0,0 +1,11 @@ +#To find the lenght of an array using slicing methodogy + +def count(a): + counti = 0 + while(a[counti:]): + counti += 1 + + return counti + +#array = [1,5,2,8,9] +#print(count(array)) diff --git a/35.FindUniqueElements/__pycache__/FindLenght.cpython-37.pyc b/35.FindUniqueElements/__pycache__/FindLenght.cpython-37.pyc new file mode 100644 index 0000000..40efef4 Binary files /dev/null and b/35.FindUniqueElements/__pycache__/FindLenght.cpython-37.pyc differ diff --git a/35.FindUniqueElements/__pycache__/builtDictionary.cpython-37.pyc b/35.FindUniqueElements/__pycache__/builtDictionary.cpython-37.pyc new file mode 100644 index 0000000..f7b7a3c Binary files /dev/null and b/35.FindUniqueElements/__pycache__/builtDictionary.cpython-37.pyc differ diff --git a/35.FindUniqueElements/__pycache__/dictionaryOperations.cpython-37.pyc b/35.FindUniqueElements/__pycache__/dictionaryOperations.cpython-37.pyc new file mode 100644 index 0000000..37975a9 Binary files /dev/null and b/35.FindUniqueElements/__pycache__/dictionaryOperations.cpython-37.pyc differ diff --git a/35.FindUniqueElements/__pycache__/find_min.cpython-37.pyc b/35.FindUniqueElements/__pycache__/find_min.cpython-37.pyc new file mode 100644 index 0000000..ac93a9b Binary files /dev/null and b/35.FindUniqueElements/__pycache__/find_min.cpython-37.pyc differ diff --git a/35.FindUniqueElements/dictionaryOperations.py b/35.FindUniqueElements/dictionaryOperations.py new file mode 100644 index 0000000..19f29e3 --- /dev/null +++ b/35.FindUniqueElements/dictionaryOperations.py @@ -0,0 +1,16 @@ +def built_dictionary(array): # To Built a dictionary + dictionary = {} #creating a empty dictionary + count = 0 + for i in array: + count = 1 + if i in dictionary: + dictionary[i] = dictionary[i] + 1 + else: + dictionary[i] = count + return dictionary + +def find_key_from_dictionary(dictionary,max_element): # To find key from the value in an dictionary + for k,v in dictionary.items(): + if (v == max_element): + key = k + return key \ No newline at end of file diff --git a/35.FindUniqueElements/findUnique.py b/35.FindUniqueElements/findUnique.py new file mode 100644 index 0000000..80e6305 --- /dev/null +++ b/35.FindUniqueElements/findUnique.py @@ -0,0 +1,17 @@ +#35. Given an unsorted integer array A containing +# elements from 0-9, find the number of unique elements. +import find_min +import dictionaryOperations +def findUnique(array): + dictionary = dictionaryOperations.built_dictionary(array) + listValues = list(dictionary.values()) + minimum_value = find_min.findMin(listValues) + for i in listValues: + if i == minimum_value : + b = (dictionaryOperations.find_key_from_dictionary(dictionary,i)) + print(b) + dictionary.pop(b) + +array = [5,7,8,2,6,5,8] +findUnique(array) +#print(built_dictionary(array)) \ No newline at end of file diff --git a/35.FindUniqueElements/find_min.py b/35.FindUniqueElements/find_min.py new file mode 100644 index 0000000..9ad5df8 --- /dev/null +++ b/35.FindUniqueElements/find_min.py @@ -0,0 +1,20 @@ + # To find the min of dictionary values +import FindLenght +def findMin(values): + + values_count = FindLenght.count(values) + one = values[0] + two = values[1] + if (one < two): + min = one + else: + min = two + i = 2 + while(i!=values_count): + if (values[i] len(array)): + shiftValue = shiftValue - len(array) + + temp = 0 + j = 0 + while (j!=shiftValue): + i = -1 + while (i!=len(array)): + array[i],temp = temp,array[i] + i += 1 + j += 1 + return array \ No newline at end of file diff --git a/37.getIndexAfterRotationright/__pycache__/Rotateright.cpython-37.pyc b/37.getIndexAfterRotationright/__pycache__/Rotateright.cpython-37.pyc new file mode 100644 index 0000000..85be44d Binary files /dev/null and b/37.getIndexAfterRotationright/__pycache__/Rotateright.cpython-37.pyc differ diff --git a/37.getIndexAfterRotationright/getindexRight.py b/37.getIndexAfterRotationright/getindexRight.py new file mode 100644 index 0000000..ee68300 --- /dev/null +++ b/37.getIndexAfterRotationright/getindexRight.py @@ -0,0 +1,12 @@ +#37. Given an unsorted integer array A, +# find the value that will be in 3rd position or index after 2 rotations to the right. +import Rotateright + +def getIndexAfterrotationRight(array,index,rotation_value): + afterRotation = Rotateright.swapRight(array,rotation_value) + return afterRotation[index] + +array = [5,7,6,9,2,8] +index = 3 +rotation_value = 2 +print(getIndexAfterrotationRight(array,index,rotation_value)) \ No newline at end of file diff --git a/38.getIndexafterrotationleft/__pycache__/shiftLeft.cpython-37.pyc b/38.getIndexafterrotationleft/__pycache__/shiftLeft.cpython-37.pyc new file mode 100644 index 0000000..a63d73c Binary files /dev/null and b/38.getIndexafterrotationleft/__pycache__/shiftLeft.cpython-37.pyc differ diff --git a/38.getIndexafterrotationleft/getindexAterrotation.py b/38.getIndexafterrotationleft/getindexAterrotation.py new file mode 100644 index 0000000..a8aa888 --- /dev/null +++ b/38.getIndexafterrotationleft/getindexAterrotation.py @@ -0,0 +1,13 @@ +#38. Given an unsorted integer array A, find the value that will be in +# 3rd position or index after 2 rotations to the left. + +import shiftLeft + +def getIndexAfterrotationLeft(array,index,rotation_value): + afterRotation = shiftLeft.shiftLeft(array,rotation_value) + return afterRotation[index] + +array = [5,7,6,9,2,8] +index = 3 +rotation_value = 2 +print(getIndexAfterrotationLeft(array,index,rotation_value)) \ No newline at end of file diff --git a/38.getIndexafterrotationleft/shiftLeft.py b/38.getIndexafterrotationleft/shiftLeft.py new file mode 100644 index 0000000..a694de4 --- /dev/null +++ b/38.getIndexafterrotationleft/shiftLeft.py @@ -0,0 +1,11 @@ +def shiftLeft(array,shiftValue): + if (shiftValue > len(array)): + shiftValue = shiftValue - len(array) + i = 0 + while(i!=shiftValue): + j = 0 + temp = (array[j]) + array.remove(array[j]) + array.append(temp) + i+=1 + return array diff --git a/39.getIndexafterrotationright/Rotateright.py b/39.getIndexafterrotationright/Rotateright.py new file mode 100644 index 0000000..41f4216 --- /dev/null +++ b/39.getIndexafterrotationright/Rotateright.py @@ -0,0 +1,13 @@ +def swapRight(array,shiftValue): + if (shiftValue > len(array)): + shiftValue = shiftValue - len(array) + + temp = 0 + j = 0 + while (j!=shiftValue): + i = -1 + while (i!=len(array)): + array[i],temp = temp,array[i] + i += 1 + j += 1 + return array \ No newline at end of file diff --git a/39.getIndexafterrotationright/__pycache__/Rotateright.cpython-37.pyc b/39.getIndexafterrotationright/__pycache__/Rotateright.cpython-37.pyc new file mode 100644 index 0000000..4535dac Binary files /dev/null and b/39.getIndexafterrotationright/__pycache__/Rotateright.cpython-37.pyc differ diff --git a/39.getIndexafterrotationright/getindexRight.py b/39.getIndexafterrotationright/getindexRight.py new file mode 100644 index 0000000..1f551db --- /dev/null +++ b/39.getIndexafterrotationright/getindexRight.py @@ -0,0 +1,12 @@ +#37. Given an unsorted integer array A, +# find the value that will be in 3rd position or index after 2 rotations to the right. +import Rotateright + +def getIndexAfterrotationRight(array,index,rotation_value): + afterRotation = Rotateright.swapRight(array,rotation_value) + return afterRotation[index] + +array = [5,7,6,9,2,8] +index = int(input("Enter the index value")) +rotation_value = int(input("Enter the rotation value")) +print(getIndexAfterrotationRight(array,index,rotation_value)) \ No newline at end of file diff --git a/4.Find_More_than_one_occurences/Find_More_than_once.py b/4.Find_More_than_one_occurences/Find_More_than_once.py new file mode 100644 index 0000000..aad8737 --- /dev/null +++ b/4.Find_More_than_one_occurences/Find_More_than_once.py @@ -0,0 +1,29 @@ +# Given an unsorted integer array A and an integer value X, find if X is found more than once in A. +#input = array +#output = if more than one element is found return true else false + +def count(a): + counti = 0 + while(a[counti:]): + counti += 1 + + return counti + +def find_more_than_once(array,search_elemnt): + flag = False + i = 0 + b = count(array) + counti = 0 + while (i!=b): + if (array[i] == search_elemnt): + counti += 1 + i += 1 + if counti == 2: + flag = True + return flag + + + +search_elemnt = 2 +array = [7,9,1,2,4] +print(find_more_than_once(array,search_elemnt)) diff --git a/4.Find_More_than_one_occurences/__pycache__/Find_More_than_once.cpython-37.pyc b/4.Find_More_than_one_occurences/__pycache__/Find_More_than_once.cpython-37.pyc new file mode 100644 index 0000000..7bcd59b Binary files /dev/null and b/4.Find_More_than_one_occurences/__pycache__/Find_More_than_once.cpython-37.pyc differ diff --git a/4.Find_More_than_one_occurences/__pycache__/test_find_more_than_one_occurrences.cpython-37-PYTEST.pyc b/4.Find_More_than_one_occurences/__pycache__/test_find_more_than_one_occurrences.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..6d2ef6a Binary files /dev/null and b/4.Find_More_than_one_occurences/__pycache__/test_find_more_than_one_occurrences.cpython-37-PYTEST.pyc differ diff --git a/4.Find_More_than_one_occurences/test_find_more_than_one_occurrences.py b/4.Find_More_than_one_occurences/test_find_more_than_one_occurrences.py new file mode 100644 index 0000000..cbd94c4 --- /dev/null +++ b/4.Find_More_than_one_occurences/test_find_more_than_one_occurrences.py @@ -0,0 +1,14 @@ +import Find_More_than_once + +def test_assertTrue(): + assert True + +def test_array_return_False(): + #arrange + search_elemnt = 2 + array = [7,9,1,2,4] + excepted = False + #act + actual = Find_More_than_once.find_more_than_once(array,search_elemnt) + #assert + assert excepted == actual \ No newline at end of file diff --git a/40.getIndexafterroationleft/__pycache__/shiftLeft.cpython-37.pyc b/40.getIndexafterroationleft/__pycache__/shiftLeft.cpython-37.pyc new file mode 100644 index 0000000..278078e Binary files /dev/null and b/40.getIndexafterroationleft/__pycache__/shiftLeft.cpython-37.pyc differ diff --git a/40.getIndexafterroationleft/getindexAterrotation.py b/40.getIndexafterroationleft/getindexAterrotation.py new file mode 100644 index 0000000..88207e6 --- /dev/null +++ b/40.getIndexafterroationleft/getindexAterrotation.py @@ -0,0 +1,13 @@ +#38. Given an unsorted integer array A, find the value that will be in +# 3rd position or index after 2 rotations to the left. + +import shiftLeft + +def getIndexAfterrotationLeft(array,index,rotation_value): + afterRotation = shiftLeft.shiftLeft(array,rotation_value) + return afterRotation[index] + +array = [5,7,6,9,2,8] +index = int(input("Enter the index value")) +rotation_value = int(input("Enter the rotation value")) +print(getIndexAfterrotationLeft(array,index,rotation_value)) \ No newline at end of file diff --git a/40.getIndexafterroationleft/shiftLeft.py b/40.getIndexafterroationleft/shiftLeft.py new file mode 100644 index 0000000..a694de4 --- /dev/null +++ b/40.getIndexafterroationleft/shiftLeft.py @@ -0,0 +1,11 @@ +def shiftLeft(array,shiftValue): + if (shiftValue > len(array)): + shiftValue = shiftValue - len(array) + i = 0 + while(i!=shiftValue): + j = 0 + temp = (array[j]) + array.remove(array[j]) + array.append(temp) + i+=1 + return array diff --git a/5.Count_Occruences_of_an_element/find_the_number_of_occurrence_of_an_element.py b/5.Count_Occruences_of_an_element/find_the_number_of_occurrence_of_an_element.py new file mode 100644 index 0000000..5a9b0ce --- /dev/null +++ b/5.Count_Occruences_of_an_element/find_the_number_of_occurrence_of_an_element.py @@ -0,0 +1,33 @@ +# Given an unsorted integer array A and an integer value X, find if X is found more than once in A. +#input = array +#output = if more than one element is found return true else false + +# Given an unsorted integer array A and an integer value X, find if X is found more than once in A. +#input = array +#output = if more than one element is found return true else false + +def count(a): + counti = 0 + while(a[counti:]): + counti += 1 + + return counti + +def find_more_than_once(array,search_elemnt): + + i = 0 + b = count(array) + counti = 0 + while (i!=b): + if (array[i] == search_elemnt): + counti += 1 + i += 1 + + return counti + + + +search_elemnt = 4 +array = [7,2,1,2,4] +count = find_more_than_once(array,search_elemnt) +print("The Number {} occurs {} times".format(search_elemnt,count)) diff --git a/6.listIndicess/list_Indices.py b/6.listIndicess/list_Indices.py new file mode 100644 index 0000000..6444d77 --- /dev/null +++ b/6.listIndicess/list_Indices.py @@ -0,0 +1,15 @@ +#6. Given an unsorted integer array A and +#an integer value X, return the indices of the locations where X is found in A. + +def getIndex(array,indexFor): + index_list = [] + i = 0 + index = 0 + + lennght = len(array) + while (i!=lennght): + if (array[i] == indexFor): + index_list.append(index) + index += 1 + i += 1 + return index_list diff --git a/7.sum/__pycache__/sum_elements.cpython-37.pyc b/7.sum/__pycache__/sum_elements.cpython-37.pyc new file mode 100644 index 0000000..a3ea2dc Binary files /dev/null and b/7.sum/__pycache__/sum_elements.cpython-37.pyc differ diff --git a/7.sum/__pycache__/test_sum.cpython-37-PYTEST.pyc b/7.sum/__pycache__/test_sum.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..87b4ec9 Binary files /dev/null and b/7.sum/__pycache__/test_sum.cpython-37-PYTEST.pyc differ diff --git a/7.sum/sum_elements.py b/7.sum/sum_elements.py new file mode 100644 index 0000000..4ad75e5 --- /dev/null +++ b/7.sum/sum_elements.py @@ -0,0 +1,22 @@ +#Given an unsorted integer array A, find the sum of all the elements in A +#input = array of any size +#output = sum of all the element of the given array + +def count(a): + counti = 0 + while(a[counti:]): + counti += 1 + + return counti + +def sum(array): + lenght_of_an_array = count(array) + sum = 0 + i = 0 + while(i!=lenght_of_an_array): + sum = sum + array[i] + i += 1 + return sum + +array = [1,5,3,6,7,3] +print(sum(array)) diff --git a/7.sum/test_sum.py b/7.sum/test_sum.py new file mode 100644 index 0000000..c39ea66 --- /dev/null +++ b/7.sum/test_sum.py @@ -0,0 +1,13 @@ +import sum_elements + +def test_AssertTrue(): + assert True + +def test_arrayreturn25(): + #arrange + array = [1,5,3,6,7,3] + excepted = 25 + #act + output = sum_elements.sum(array) + #assert + assert excepted == output \ No newline at end of file diff --git a/8.Find_Mean/FindLenght.py b/8.Find_Mean/FindLenght.py new file mode 100644 index 0000000..d2c9e33 --- /dev/null +++ b/8.Find_Mean/FindLenght.py @@ -0,0 +1,11 @@ +#To find the lenght of an array using slicing methodogy + +def count(a): + counti = 0 + while(a[counti:]): + counti += 1 + + return counti + +#array = [1,5,2,8,9] +#print(count(array)) diff --git a/8.Find_Mean/Find_mean.py b/8.Find_Mean/Find_mean.py new file mode 100644 index 0000000..c4c725f --- /dev/null +++ b/8.Find_Mean/Find_mean.py @@ -0,0 +1,14 @@ +#8. Given an unsorted integer array A, find the mean. + +import Sum +import FindLenght + +def mean(array): + sum = Sum.sum(array) + print(sum) + divide_value = FindLenght.count(array) + mean = sum / divide_value + return mean + +array = [4,2,6,7,3] +print(mean(array)) diff --git a/8.Find_Mean/Sum.py b/8.Find_Mean/Sum.py new file mode 100644 index 0000000..1d87ee7 --- /dev/null +++ b/8.Find_Mean/Sum.py @@ -0,0 +1,17 @@ +#Given an unsorted integer array A, find the sum of all the elements in A +#input = array of any size +#output = sum of all the element of the given array + +import FindLenght + +def sum(array): + lenght_of_an_array = FindLenght.count(array) + sum = 0 + i = 0 + while(i!=lenght_of_an_array): + sum = sum + array[i] + i += 1 + return sum + +#array = [1,5,3,6,7,3] +#print(sum(array)) diff --git a/8.Find_Mean/__pycache__/FindLenght.cpython-37.pyc b/8.Find_Mean/__pycache__/FindLenght.cpython-37.pyc new file mode 100644 index 0000000..6485681 Binary files /dev/null and b/8.Find_Mean/__pycache__/FindLenght.cpython-37.pyc differ diff --git a/8.Find_Mean/__pycache__/Find_mean.cpython-37.pyc b/8.Find_Mean/__pycache__/Find_mean.cpython-37.pyc new file mode 100644 index 0000000..73e6a16 Binary files /dev/null and b/8.Find_Mean/__pycache__/Find_mean.cpython-37.pyc differ diff --git a/8.Find_Mean/__pycache__/Finding_lenght_of_an_array_without_using_len_functin.cpython-37.pyc b/8.Find_Mean/__pycache__/Finding_lenght_of_an_array_without_using_len_functin.cpython-37.pyc new file mode 100644 index 0000000..7e22f14 Binary files /dev/null and b/8.Find_Mean/__pycache__/Finding_lenght_of_an_array_without_using_len_functin.cpython-37.pyc differ diff --git a/8.Find_Mean/__pycache__/Sum.cpython-37.pyc b/8.Find_Mean/__pycache__/Sum.cpython-37.pyc new file mode 100644 index 0000000..ac2b3c2 Binary files /dev/null and b/8.Find_Mean/__pycache__/Sum.cpython-37.pyc differ diff --git a/8.Find_Mean/__pycache__/find_mean_of_array_elements.cpython-37.pyc b/8.Find_Mean/__pycache__/find_mean_of_array_elements.cpython-37.pyc new file mode 100644 index 0000000..68cb1eb Binary files /dev/null and b/8.Find_Mean/__pycache__/find_mean_of_array_elements.cpython-37.pyc differ diff --git a/8.Find_Mean/__pycache__/find_sum_of_an_array.cpython-37.pyc b/8.Find_Mean/__pycache__/find_sum_of_an_array.cpython-37.pyc new file mode 100644 index 0000000..b9d0aa9 Binary files /dev/null and b/8.Find_Mean/__pycache__/find_sum_of_an_array.cpython-37.pyc differ diff --git a/8.Find_Mean/__pycache__/test_find_mean_of_array_elements.cpython-37-PYTEST.pyc b/8.Find_Mean/__pycache__/test_find_mean_of_array_elements.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..3824e87 Binary files /dev/null and b/8.Find_Mean/__pycache__/test_find_mean_of_array_elements.cpython-37-PYTEST.pyc differ diff --git a/8.Find_Mean/test_find_mean.py b/8.Find_Mean/test_find_mean.py new file mode 100644 index 0000000..7d49484 --- /dev/null +++ b/8.Find_Mean/test_find_mean.py @@ -0,0 +1,13 @@ +import Find_mean + +def test_AssertTrue(): + assert True + +def test_arrayreturn25(): + #arrange + array = [4,2,6,7,3] + excepted = 4.4 + #act + actual = Find_mean.mean(array) + #asert + assert excepted == actual \ No newline at end of file diff --git a/9.Most_occurence.py/Equate.py b/9.Most_occurence.py/Equate.py new file mode 100644 index 0000000..3b16ed7 --- /dev/null +++ b/9.Most_occurence.py/Equate.py @@ -0,0 +1,25 @@ +import FindLenght + +def Equate(array): + #flag = False + Lenght = FindLenght.count(array) + i = 0 + while (i!=Lenght): + check = array[i] + j = i+1 + while (j!=Lenght): + if (check == array[j]): + flag = False + else: + flag = True + break + j += 1 + i += 1 + + return flag + + + +#array = [1,1,1,1] +#array = [1,2,6,7] +#print(Equate(array)) \ No newline at end of file diff --git a/9.Most_occurence.py/FindLenght.py b/9.Most_occurence.py/FindLenght.py new file mode 100644 index 0000000..d2c9e33 --- /dev/null +++ b/9.Most_occurence.py/FindLenght.py @@ -0,0 +1,11 @@ +#To find the lenght of an array using slicing methodogy + +def count(a): + counti = 0 + while(a[counti:]): + counti += 1 + + return counti + +#array = [1,5,2,8,9] +#print(count(array)) diff --git a/9.Most_occurence.py/Max.py b/9.Most_occurence.py/Max.py new file mode 100644 index 0000000..02504dd --- /dev/null +++ b/9.Most_occurence.py/Max.py @@ -0,0 +1,20 @@ + # To find the max of dictionary values +import FindLenght +def Max(values): + + values_count = FindLenght.count(values) + one = values[0] + two = values[1] + if (one > two): + max = one + else: + max = two + i = 2 + while(i!=values_count): + if (values[i]>max): + max = values[i] + i += 1 + return max + +#values = [5,2,4,7,3,5] +#print(Max(values)) \ No newline at end of file diff --git a/9.Most_occurence.py/__pycache__/Equate.cpython-37.pyc b/9.Most_occurence.py/__pycache__/Equate.cpython-37.pyc new file mode 100644 index 0000000..5e690f7 Binary files /dev/null and b/9.Most_occurence.py/__pycache__/Equate.cpython-37.pyc differ diff --git a/9.Most_occurence.py/__pycache__/FindLenght.cpython-37.pyc b/9.Most_occurence.py/__pycache__/FindLenght.cpython-37.pyc new file mode 100644 index 0000000..d88800a Binary files /dev/null and b/9.Most_occurence.py/__pycache__/FindLenght.cpython-37.pyc differ diff --git a/9.Most_occurence.py/__pycache__/Max.cpython-37.pyc b/9.Most_occurence.py/__pycache__/Max.cpython-37.pyc new file mode 100644 index 0000000..6ab21f2 Binary files /dev/null and b/9.Most_occurence.py/__pycache__/Max.cpython-37.pyc differ diff --git a/9.Most_occurence.py/__pycache__/find_most_occurence.cpython-37.pyc b/9.Most_occurence.py/__pycache__/find_most_occurence.cpython-37.pyc new file mode 100644 index 0000000..da31ff8 Binary files /dev/null and b/9.Most_occurence.py/__pycache__/find_most_occurence.cpython-37.pyc differ diff --git a/9.Most_occurence.py/__pycache__/test_Most_occurence.cpython-37-PYTEST.pyc b/9.Most_occurence.py/__pycache__/test_Most_occurence.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..048673f Binary files /dev/null and b/9.Most_occurence.py/__pycache__/test_Most_occurence.cpython-37-PYTEST.pyc differ diff --git a/9.Most_occurence.py/__pycache__/test_find_most_occurence_of_an_element.cpython-37-PYTEST.pyc b/9.Most_occurence.py/__pycache__/test_find_most_occurence_of_an_element.cpython-37-PYTEST.pyc new file mode 100644 index 0000000..e00aa39 Binary files /dev/null and b/9.Most_occurence.py/__pycache__/test_find_most_occurence_of_an_element.cpython-37-PYTEST.pyc differ diff --git a/9.Most_occurence.py/find_most_occurence.py b/9.Most_occurence.py/find_most_occurence.py new file mode 100644 index 0000000..5622439 --- /dev/null +++ b/9.Most_occurence.py/find_most_occurence.py @@ -0,0 +1,37 @@ +import FindLenght +import Max +import Equate + +def built_dictionary(array): # To Built a dictionary + d = {} #creating a empty dictionary + count = 0 + for i in array: + count = 1 + if i in d: + d[i] = d[i] + 1 + else: + d[i] = count + return d + +def find_key_from_dictionary(dictionary,max_element): # To find key from the value in an dictionary + for k,v in dictionary.items(): + if (v == max_element): + key = k + return key + +def find_most_occureence(array): # the main function + dictionary = built_dictionary(array) + values = list(dictionary.values()) # converting the dictonary value to a list + if (Equate.Equate(values)): + max_element = Max.Max(values) + key = find_key_from_dictionary(dictionary,max_element) + print ("the number {1} appears {0} times".format(max_element,key)) + else: + print ("Can't find the most occurence of an element") + + +#array = [1,2,5,3,2,4,5,5,5] +#array = [2,6,2,7,2,8,2] +#array = [4,3,2,4,5,4] +array = [1,2,3,4,5] +find_most_occureence(array) \ No newline at end of file diff --git a/9.Most_occurence.py/test_Most_occurence.py b/9.Most_occurence.py/test_Most_occurence.py new file mode 100644 index 0000000..6274537 --- /dev/null +++ b/9.Most_occurence.py/test_Most_occurence.py @@ -0,0 +1,6 @@ +import find_most_occurence + +def test_assertTrue(): + assert True + +def \ No newline at end of file diff --git a/Questions.md b/Questions.md deleted file mode 100644 index 0e47ccc..0000000 --- a/Questions.md +++ /dev/null @@ -1,54 +0,0 @@ -# Programs on Unsorted Integer Arrays - -## Note: If there is a case where the solution provided will create a problem if negative integers are present in the array, then explicitly specify then same and if possible, provide an alternate soltuion that will eliminate the problem with negative integers. - -1. Find the length of the given integer array. Don't use the len() function. -2. Given an unsorted integer array A and an integer value X, find if A contains the value X. -3. Given an unsorted integer array A and an integer value X, return the index at which X is located in A or return -1 if it is not found in A. -4. Given an unsorted integer array A and an integer value X, find if X is found more than once in A. -5. Given an unsorted integer array A and an integer value X, return the number of times X is found in A. -6. Given an unsorted integer array A and an integer value X, return the indices of the locations where X is found in A. -7. Given an unsorted integer array A, find the sum of all the elements in A. -8. Given an unsorted integer array A, find the mean. -9. Given an unsorted integer array A, find the number that occurs the most or find the mode of the array. -10. Given an unsorted integer array A, find the smallest number. -11. Given an unsorted integer array A, find the largest number. -12. Given an unsorted integer array A, find the number of times the smallest number is found in the array. -13. Given an unsorted integer array A, find the number of times the largest number is found in the array. -14. Given an unsorted integer array A, print the contents of the array in the given format: {arrayindex:value, arrayindex:value}. Note that there is no comma after the last value. -15. Write a function that takes two unsorted integer arrays as input and returns True if the two arrays are the same. -16. Wrtie a function that takes an unsorted integer array as input and returns a copy of the array as output. -17. Write a function that takes an unsorted integer array as input and prints the contents of the array in reverse order. -18. Write a function that takes an unsorted integer array as input and returns an array with the values in reverse order. -19. Write a function that takes two unsorted integer arrays as input and returns the index upto which they are identical. Return -1 otherwise. -20. Write a function that takes an unsorted integer array as input and returns an array with the duplicates removed. -21. Given an unsorted integer array as input, return the number of odd numbers in it. -22. Given an unsorted integer array as input, return the number of even numbers in it. -23. Given an unsorted integer array as input, return the number of prime numbers in it. -24. Given an unsorted integer array as input, return the number of perfect squares in it. -25. Given an unsorted integer array as input, find the second largest/smallest element in the array. -26. Given an unsorted integer array as input, find the Kth largest/smallest element in the array. -27. Given an unsorted integer array and an integer value X as input, return the count of the values less than or equal to X. -28. Given an unsorted integer array and an integer value X as input, return the count of the values greater than or equal to X. -29. Given an unsorted integer array as input, rotate the contents of the array to the right by 1 position. -30. Given an unsorted integer array as input, rotate the contents of the array to the left by 1 position. -31. Given an unsorted integer array as input, rotate the contents of the array to the right by 2 positions. -32. Given an unsorted integer array of length N as input, rotate the contents of the array to the right/left by K positions, where K is always less than N. -33. Given an unsorted integer array of length N as input, rotate the contents of the array to the right/left by K positions, where K could be greater than N. -34. Given an unsorted integer array, return the count of the elements with values that falls within a given range. -35. Given an unsorted integer array A containing elements from 0-9, find the number of unique elements. -36. Given an unsorted integer array A containing elements from 0-9, count the number of times each number appears. -37. Given an unsorted integer array A, find the value that will be in 3rd position or index after 2 rotations to the right. -38. Given an unsorted integer array A, find the value that will be in 3rd position or index after 2 rotations to the left. -39. Given an unsorted integer array A, find the value that will be in index "I" after "R" rotations to the right. -40. Given an unsorted integer array A, find the value that will be in index "I" after "R" rotations to the left. -41. 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 (Subset sum for a pair). -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. -43. 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 values that adds upto X. -44. Given an unsorted integer array A and a value X, check if there exists a subset of A of size three that adds upto X. -45. Given an unsorted integer array A and a value X, check if there exists a subset of A of size three that adds upto X and print the values that adds upto X. -46. Given an unsorted integer array A and a value X, find the minimum size of the subset required, such that the values of the subset adds upto X. Also print the elements of that subset. -47. Given an unsorted integer array A and a value X, find the maximum size of the subset that could be formed, such that the values of the subset adds upto X. Also print the elements of that subset. -48. Given an unsorted integer array A and a value X, return the subset of A containing values that are multiples of X. Return -1 otherwise. -49. Given an unsorted integer array A, check if the array A is a palindrome or not. -50. Given an unsorted integer array A, find the sum and product of the minimum and maximum values of the array. diff --git a/README.md b/README.md deleted file mode 100644 index 66e621c..0000000 --- a/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Questions on Unsorted Arrays - -### For Students of ROOT IT LEARNING CENTRE, TRICHY - -## Instructions: Fork the repository, add your solutions and give pull requests for evaluation - -For Details Contact: - -P.ANANDKUMAR - -Mobile: 9790636324 - -Email: root.anand@gmail.com - -www.therootlearning.com diff --git a/removeDuplicatesonly/findLenght.py b/removeDuplicatesonly/findLenght.py new file mode 100644 index 0000000..61ac828 --- /dev/null +++ b/removeDuplicatesonly/findLenght.py @@ -0,0 +1,18 @@ +Question : +========== + To find the lenght of an array using slicing methodogy +Input : +======= + Unsorted Integer Array +Output: +======= + Count the No of Element in the Array - Integer +Code: +===== +def FindLenght(array): + count = 0 + while(a[count:]): + count += 1 + return count + + diff --git a/removeDuplicatesonly/issorted.py b/removeDuplicatesonly/issorted.py new file mode 100644 index 0000000..4f418db --- /dev/null +++ b/removeDuplicatesonly/issorted.py @@ -0,0 +1,28 @@ +problem statement : +=================== + Function to check whether the given array is sorted or not +Input : +======= + Integer Array + + Output : + ======== + True - if sorted - Bool + False - if not sorted - Bool + +Code : +===== +import findLenght +def isSorted(array): # To Check whether array is sorted or not + + flag = True + lenght = findLenght.getLenght(array) + + if lenght == 0 or lenght == 1: + return True + iteratorValue = 0 + while (i!=lenght-1): + if array[iteratorValue] > array[iteratorValue+1]: + flag = False + iteratorValue+=1 + return flag diff --git a/removeDuplicatesonly/mainCode b/removeDuplicatesonly/mainCode new file mode 100644 index 0000000..480d043 --- /dev/null +++ b/removeDuplicatesonly/mainCode @@ -0,0 +1,28 @@ +Problem Statement : +================== + To remove non duplicate elements + +Input : +======= + Integer array +ouput : +====== + Contain only single value non dulipcate elements + +Code : +====== + +def Main(array): + if isSorted(array): + array = removeDuplicate(array) + else : + array.sort() + array = removeDuplicate(array) + + untill = (array.pop())+1 + for i in range(0,untill): + print(array[i], end="") + if i != untill-1 : + print(",",end = " ") + + return array diff --git a/removeDuplicatesonly/removeNonDuplicate.py b/removeDuplicatesonly/removeNonDuplicate.py new file mode 100644 index 0000000..c2d51eb --- /dev/null +++ b/removeDuplicatesonly/removeNonDuplicate.py @@ -0,0 +1,29 @@ +"""problem Statement : + =================== + To remove the Non Duplicte element from the array + +Input : +======= + Integer Array +Output : +======== + Contains non Duplicate elements + +Code : +====== +def removeDuplicate(array): # To remove the Duplicate Element form the Array + j = 0 + i = 0 + count = 0 + lenght = getLenght(array) -1 + while(i!=lenght): + if (array[i] != array[i+1]): + array[j] = array[i] + #print(array[i]) + count += 1 + j += 1 + i += 1 + + array[j] = array[-1] + array.append(count) + return array