This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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[] = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Tuple | |
def gcd(a: int, b: int) -> int: | |
""" | |
Simple recursive implementation of Euclidean algorithm | |
""" | |
a, b = abs(a), abs(b) | |
if b == 0: | |
return a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import reduce | |
def merge(lst1, lst2): | |
"""Merges two sorted lists. | |
>>> s1 = [1, 3, 5] | |
>>> s2 = [2, 4, 6] | |
>>> merge(s1, s2) | |
[1, 2, 3, 4, 5, 6] | |
>>> s1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def digital_root(n: int, original=None) -> int: | |
""" | |
Return the digital root of a non-negative integer `n`. Note that this is | |
basically the same as `n % 9` except in the special case when `n` is a | |
multiple of 9. | |
@param n: A non-negative integer | |
@type n: int | |
@return: The digital root of `n` |