Skip to content

Instantly share code, notes, and snippets.

View Clivern's full-sized avatar

Ahmed Clivern

View GitHub Profile
@Clivern
Clivern / python_linked_lists.py
Created March 21, 2021 18:42
Python Linked Lists
import bisect
from heapq import *
"""
Linked Lists
A linked list is an ordered collection of values.
Linked lists are similar to arrays in the sense that they contain objects in a linear order.
However they differ from arrays in their memory layout.
@Clivern
Clivern / python_deque.py
Created March 21, 2021 18:43
Python Deque
class Deque():
"""Deque DST"""
def __init__(self):
self._items = []
def add_front(self, item):
"""
Add to the front
"""
@Clivern
Clivern / python_binary_tree.py
Created March 21, 2021 18:44
Python Binary Tree
""""
Trees
Trees are well known as a non-linear Data Structure. It doesn’t store data in a linear way. It organizes data in a hierarchical way.
- Root: the topmost node of the tree
- Edge: the link between 2 nodes
- Child: a node that has a parent node
- Parent: a node that has an edge to a child node
- Leaf: a node that does not have a child node in the tree
@Clivern
Clivern / python_linked_list.py
Created March 24, 2021 20:57
Python Linked List
class SingleNode():
def __init__(self, data=None, next=None):
self.data = data
self.next = next
def __repr__(self):
return repr(self.data)
class DoubleNode():
@Clivern
Clivern / cci.py
Created March 24, 2021 20:59
Cracking the Coding Interview Solutions Chapter 1
from collections import Counter
def is_unique(word):
# O(N)
# ASCII Table Chars
chars_set = [False for i in range(128)]
for char in word:
val = ord(char)
@Clivern
Clivern / array_dominator.py
Created March 27, 2021 20:29
Gets the index of the dominator of array A
from collections import Counter
def solution(A):
"""Gets the index of the dominator of array A"""
counter = Counter()
for i, v in enumerate(A):
counter[v] += 1
counter = counter.most_common()
@Clivern
Clivern / peak.py
Created March 27, 2021 21:12
Get array peak values
def solution(A):
count = 0
peaks = []
for i in range(len(A)):
if i > 0 and i != (len(A)-1) and A[i] > A[i-1] and A[i] > A[i+1] and A[i] not in peaks:
peaks.append(A[i])
count += 1
return count
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Clivern
Clivern / github_apps.md
Last active April 27, 2021 12:07
Authenticating with GitHub Apps
@Clivern
Clivern / github-api-create-pull-request-end-to-end.py
Created April 26, 2021 22:44 — forked from nottrobin/github-api-create-pull-request-end-to-end.py
With Github API v3, create branch, commit a change to a file and open a pull request
#! /usr/bin/env python
from base64 import b64decode
from github import Github
with open('access-token.txt') as token_file:
token = token_file.read().strip()
api = Github(token)
site = api.get_repo('nottrobin/gh-cms-example-site')