Skip to content

Instantly share code, notes, and snippets.

@bhuiyanmobasshir94
Created April 1, 2023 17:01
Show Gist options
  • Save bhuiyanmobasshir94/7dc5c9d3e54653e9e658a50a56c6535f to your computer and use it in GitHub Desktop.
Save bhuiyanmobasshir94/7dc5c9d3e54653e9e658a50a56c6535f to your computer and use it in GitHub Desktop.
# Problem Set: 1
x = 121
# x = -121
# x = 10
def is_plaindrom(x):
strs = str(x)
l,r = 0, len(strs) -1
while l < r:
if strs[l] != strs[r]:
return False
l += 1
r -= 1
return True
# Problem Set: 2
nums = [2,2,1]
# nums = [4,1,2,1,2]
# nums = [1]
def find_singleone(nums):
hashMap = {}
res = nums[0]
for num in nums:
hashMap[num] = 1 + hashMap.get(num, 0)
for key, value in hashMap.items():
if value == 1:
return key
# Problem Set: 3
# bills = [5,5,5,10,20]
# bills = [5,5,10,10,20]
# bills = [5, 10, 5, 20, 20]
# bills = [20, 10, 5]
# bills = [10, 5, 5]
# bills = [5, 10, 5, 5, 20]
bills = [5, 5, 5, 10, 20]
def can_give_correct_change(bills):
count_in_five = 0
for bill in bills:
if bill == 5:
count_in_five += 1
else:
to_give_in_five = (bill - 5) // 5
if count_in_five < to_give_in_five:
return False
else:
count_in_five -= to_give_in_five
count_in_five += 1
return True
if __name__ == "__main__":
print(is_plaindrom(x))
print(find_singleone(nums))
print(can_give_correct_change(bills))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment