Skip to content

Instantly share code, notes, and snippets.

View Per48edjes's full-sized avatar
👉
This is a good point.

Ravi Dayabhai Per48edjes

👉
This is a good point.
View GitHub Profile
@Per48edjes
Per48edjes / climbing_stairs.py
Last active April 29, 2023 03:25
LeetCode 70. Climbing Stairs
"""
You are climbing a staircase. It takes `n` steps to reach the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
"""
from functools import lru_cache
@lru_cache
@Per48edjes
Per48edjes / longest_increasing_subsequence.py
Created July 4, 2022 11:55
LeetCode 300. Longest Increasing Subsequence
"""
Given an integer array nums, return the length of the longest strictly
increasing subsequence.
A subsequence is a sequence that can be derived from an array by deleting some
or no elements without changing the order of the remaining elements. For
example, [3,6,2,7] is a subsequence of the array [0,3,1,6,2,2,7].
"""
from typing import List
@Per48edjes
Per48edjes / integer_partitions.py
Last active August 21, 2022 13:40
Partitioning integer `n` using parts up to size `m`
#!/usr/bin/env python3
"""
Problem statement:
- https://composingprograms.com/pages/17-recursive-functions.html#example-partitions
- https://youtu.be/ngCos392W4w?t=678
"""
from functools import lru_cache
@Per48edjes
Per48edjes / insertion_sort.c
Created June 18, 2022 00:36
Implementation of insertion sort on array of integers in C
#include <stdio.h>
#include <stdlib.h>
void swap(int *a, int *b);
void insert(int *subseq, int subseq_len);
void print_array(int *arr, int len_arr);
int main(void)
{
int items[] = {
@Per48edjes
Per48edjes / merge_sort.c
Last active May 28, 2022 04:44
Implementation of merge sort on array of integers in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int * merge_sort(int *parr, int arr_len);
void print_array(int *arr, int len_arr);
int main(void)
{
@Per48edjes
Per48edjes / binary_search.c
Last active May 28, 2022 02:53
Implementation of binary search on sorted array of integers in C
#include <stdio.h>
#include <stdlib.h>
int binary_search(const int *arr, const int arr_len, const int n);
int main(int argc, char *argv[])
{
if (argc != 2)
{
@Per48edjes
Per48edjes / bubble_sort.c
Last active May 27, 2022 03:42
Implementation of bubble sort on array of integers in C
#include <stdio.h>
void swap(int *a, int *b);
void print_array(int *arr, int len_arr);
int main(void)
{
int items[] = { 5, 2, 7, 4, 1, 6, 3, 0 };
@Per48edjes
Per48edjes / selection_sort.c
Last active May 26, 2022 20:21
Implementation of selection sort on array of integers in C
#include <stdio.h>
void swap(int *a, int *b);
void print_array(int *arr, int len_arr);
int main(void)
{
int items[] = { 5, 2, 7, 4, 1, 6, 3, 0 };
@Per48edjes
Per48edjes / name_strings_as_integers.c
Last active May 28, 2022 01:35
Encoding strings as integers, vice versa in C
#include <stdio.h>
#include <string.h>
/*
* Extra credit: If an array of characters is 4 bytes long, and an integer is 4
* bytes long, then can you treat the whole in_name array like it’s just an
* integer?
*/
@Per48edjes
Per48edjes / tictactoe.py
Last active March 20, 2022 08:47
Tic-Tac-Toe game for Recurse Center code interview
"""
Recurse Center Programming Task: Tic-Tac-Toe
Author: Ravi Dayabhai
"""
from __future__ import annotations
import copy
import math
import os