Skip to content

Instantly share code, notes, and snippets.

@Ruhshan
Created February 26, 2023 16:57
Show Gist options
  • Save Ruhshan/4a71142476cb23708d43777c22e44af0 to your computer and use it in GitHub Desktop.
Save Ruhshan/4a71142476cb23708d43777c22e44af0 to your computer and use it in GitHub Desktop.
## solution to problem 1
def is_palindrome(n):
if n < 0:
return False
s = str(n)
flag = 0
for c in s[:len(s)/2]:
flag+=int(c)
middle = len(s)/2 if len(s)%2 == 0 else 1+len(s)/2
for c in s[middle:]:
flag -= int(c)
if flag == 0:
return True
return False
# solution to problem 2
from collections import defaultdict
def find_unique_element(arr):
count = defaultdict(int)
for element in arr:
count[element]+=1
for element, occurance in count.items():
if occurance == 1:
return element
# solution to problem 3
def check_changes(bills):
current_total = 0
for bill in bills:
if bill > 5:
change = bill - 5
if change > current_total:
return False
else:
current_total-=change
current_total+=5
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment