Skip to content

Commit

Permalink
Adds count even and odds, functions in list and intro to list solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
omonimus1 committed Jun 10, 2020
1 parent 36296b6 commit 35d07d2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ My solutions to competitive programming problems in [Geeks for Geeks](https://au
|Find immediate smaller than X|[C++](c++/find_immediate_smaller_than_x.cpp)|
|Kth Smallest Element|[C++](c++/kth-smallest-number.cpp)|
|Alone in Couple|[C++](c++/alone-in-couple.cpp)|
|Intro to list|[Python](python/intro-to-list.py)|
|Count even odd python|[Python](python/count-even-odd-python.py)|
|Functions in list|[Python](python/functions-in-list.py)|
|Pair sum in vector(sum second element of the second element)|[C++](c++/pair-sum-in-vector.cpp)|
|Index of the first repeating element |[C++](c++/first-repeating-element.cpp)|
|K-th element of two sorted Arrays(merge of two arrays)|[C++](c++/k-th-element-of-two-sorted-arrays.cpp)|
Expand Down
19 changes: 19 additions & 0 deletions python/count-even-odd-python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# https://practice.geeksforgeeks.org/problems/count-even-odd-python/1/?track=python-module-5&batchId=119
def count_even_odd(n, arr):
c_e = 0
c_o = 0

pair = list()

# your code here
for x in arr:
if x%2 == 0:
c_e += 1
else:
c_o += 1

pair.append(c_e)
pair.append(c_o)

return pair

24 changes: 24 additions & 0 deletions python/functions-in-list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# https://practice.geeksforgeeks.org/problems/functions-in-lists-python/1/?track=python-module-5&batchId=11

# Function to sort the list
def sort_arr(arr):
arr.sort()

# Function to join list elements
# with string as delimiter
def join_list(arr, string):
return string.join(arr)


# Function to reverse array elements
def rev_arr(arr):
arr.reverse()

# Function to insert element at index
def insert_arr(arr, index, element):
arr.insert(index, element)

# Function to pop element from array at index
def pop_arr(arr, index):
arr.pop(index)

9 changes: 9 additions & 0 deletions python/intro-to-list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# https://practice.geeksforgeeks.org/problems/intro-to-lists-python/1/?track=python-module-5&batchId=119
def check_zero(size_array, arr):

# complete the if statement to check
# if first or last element in list is 0
if arr[0] == 0 or arr[size_array-1] == 0 :
return True

return False

0 comments on commit 35d07d2

Please sign in to comment.