Skip to content

Instantly share code, notes, and snippets.

View ak9999's full-sized avatar
🎯
Focusing

Abdullah "AJ" Khan ak9999

🎯
Focusing
View GitHub Profile
@ak9999
ak9999 / leetcode_problem.txt
Last active March 5, 2021 02:26
Mob programming solutions to the Ransom Note problem from Leetcode: https://leetcode.com/problems/ransom-note/
Link: https://leetcode.com/problems/ransom-note/
Given an arbitrary ransom note string and another string containing letters from all the magazines,
write a function that will return true if the ransom note can be constructed from the magazines;
otherwise, it will return false.
Each letter in the magazine string can only be used once in your ransom note.
Example 1:
Input: ransomNote = "a", magazine = "b"
@ak9999
ak9999 / two_sum.py
Created May 12, 2021 23:21
Two Sum Problem Solution
from typing import List
class Solution:
def binary_search(self, container: List[int], key):
low = 0
high = len(container) - 1
while (low <= high):
middle = (low + high) >> 1
middle_value = container[middle]
if middle_value < key:
@ak9999
ak9999 / const_demo.cpp
Created January 2, 2022 02:15
Demo on using `const`.
#include <iostream>
static int outside_variable{0};
class Demo {
int val;
public:
static const int inside{1};
Demo(int v = 0) {
val = v;
@ak9999
ak9999 / absolute-to-canonical-paths.py
Created January 2, 2022 02:18
Leetcode problems I did in February 2021
# Link: https://leetcode.com/explore/challenge/card/february-leetcoding-challenge-2021/584/week-1-february-1st-february-7th/3629/
# Given a string path, which is an absolute path (starting with a slash '/') to a file or directory in a Unix-style file system, convert it to the simplified canonical path.
# In a Unix-style file system, a period '.' refers to the current directory, a double period '..' refers to the directory up a level, and any multiple consecutive slashes (i.e. '//') are treated as a single slash '/'. For this problem, any other format of periods such as '...' are treated as file/directory names.
# The canonical path should have the following format:
# The path starts with a single slash '/'.
# Any two directories are separated by a single slash '/'.
# The path does not end with a trailing '/'.
@ak9999
ak9999 / missing_number.py
Created January 2, 2022 02:25
Missing number problem from Leetcode
# https://leetcode.com/problems/missing-number/
import random
def generate_input_array(n: int) -> list:
if not (1 <= n <= 104):
raise ValueError('Given `n` does not fulfill 1 <= n <= 104')
nums = list()
while len(nums) != n:
temp = random.randint(0, n)