Skip to content

Instantly share code, notes, and snippets.

View imedadel's full-sized avatar
🏗️
Building something

Imed Adel imedadel

🏗️
Building something
View GitHub Profile
git checkout master
git pull
git checkout mobiledevicesupport
git merge master

to keep mobiledevicesupport in sync with master

for file in *.html
do
mv "$file" "${file%.html}.txt"
done
def carParkingRoof(cars, k):
if k == 1: return 1
cars.sort()
roof = cars[-1]-cars[0]+1
if k == len(cars): return roof
for car in range(k-1, len(cars)):
roof = min(roof, cars[car] - cars[car-k+1] + 1)
def has_cycle(head):
if head is None or head.next is None or head.next.next is None:
return False
count = 0
while head.next:
head = head.next
count += 1
if count > 100:
return True
return False
def insertNodeAtPosition(head, data, position):
if position == 0:
new_node = SinglyLinkedListNode(data)
new_node.next = head
return new_node
tmp = head
for i in range(position-1):
tmp = tmp.next
new_node = SinglyLinkedListNode(data)
def reverse(head):
curr = new_head = head
while curr:
print(curr.data)
curr.prev, curr.next = curr.next, curr.prev
new_head = curr
curr = curr.prev
return new_head
def isBalanced(s):
stack = [s[0]]
for c in s[1:]:
if len(stack) == 0:
stack.append(c)
elif (c == ")" and stack[-1] == "(") or (c == "}" and stack[-1] == "{") or (c == "]" and stack[-1] == "["):
stack.pop()
else:
stack.append(c)
return "YES" if len(stack) == 0 else "NO"
def candies(n, arr):
if len(arr) == 1:
return 1
candies = [1]*len(arr)
candies[0] = 1
for i in range(1, len(arr)):
if arr[i] > arr[i-1]:
candies[i] = candies[i] + candies[i-1]
q = int(input().strip())
def abbr(a, b):
grid = [[0 for _ in range(len(b)+1)] for _ in range(len(a)+1)]
longest = 0
for i in range(len(a)+1):
for j in range(len(b)+1):
if j == 0 or i == 0:
grid[i][j] = 0
# Create an array to track the max sum
# The max could be either the current value, the current max, or the current value plus the max of arr[i-2]
def maxSubsetSum(arr):
maxTop = max(arr[0], arr[1])
maxes = [arr[0], maxTop]
for i in range(2, len(arr)):
localMax = max(max(arr[i], maxTop), maxes[i-2]+arr[i])
maxes.append(localMax)