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
| import { | |
| Dispatch, | |
| ReactNode, | |
| useContext, | |
| useReducer, | |
| createContext, | |
| } from "react"; | |
| export interface StoreProviderProps { | |
| children?: ReactNode; |
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
| function replaceZeros(input: string): number { | |
| let zeroes = 0; | |
| const res = input | |
| .split("") | |
| .reduce((acc: string[], curr, index, digits) => { | |
| const next = digits[index + 1]; | |
| if (curr === "0" && next === "0") { | |
| zeroes++; |
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
| package main | |
| import "fmt" | |
| func main() { | |
| res1 := maxSubArray([]int{-4, 2, -5, 1, 2, 3, 6, -5, 1}, 4) | |
| fmt.Println(res1) | |
| res2 := maxSubArray([]int{1, 2, 0, 5}, 2) | |
| fmt.Println(res2) | |
| } |
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
| package main | |
| import ( | |
| "fmt" | |
| "strconv" | |
| ) | |
| func main() { | |
| val1 := missingBits([]int{1, 2, 3, 4, 20, 21, 22, 23}) | |
| fmt.Println(val1) |
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
| type Query { | |
| hello: String! | |
| allPosts(query: PostsQuery): [Post!]! | |
| featuredPosts(query: PostsQuery): [Post!]! | |
| postsInCategory(categoryId: Int!, query: PostsQuery): [Post!]! | |
| allTags(query: TagsQuery): [Tag] | |
| viewer: User! | |
| } | |
| type Post { |
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
| pub fn repeated_groups(numbers: &[u32]) -> Vec<Vec<u32>> { | |
| numbers | |
| .iter() | |
| .fold::<Vec<Vec<u32>>, _>(vec![], |mut acc, &n| { | |
| if let Some(last) = acc.last_mut() { | |
| if last[0] == n { | |
| last.push(n); | |
| } else { | |
| acc.push(vec![n]); | |
| } |
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
| function scramble(sentences: string[]): string { | |
| return sentences | |
| .map((sentence) => | |
| sentence | |
| .split(" ") | |
| .map((word) => { | |
| if (word.length <= 3) { | |
| return word; | |
| } |
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
| use anyhow::{anyhow, Error, Result}; | |
| use std::{fmt::Display, str::FromStr}; | |
| #[derive(Debug, PartialEq, Eq)] | |
| struct Fraction { | |
| top: isize, | |
| bottom: isize, | |
| } | |
| impl FromStr for Fraction { |
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
| use std::str::FromStr; | |
| #[derive(Debug)] | |
| struct Rgb { | |
| r: u8, | |
| g: u8, | |
| b: u8, | |
| } | |
| impl FromStr for Rgb { |
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
| type Point = [number, number]; | |
| const slope = ([x1, y1]: Point, [x2, y2]: Point) => (y2 - y1) / (x2 - x1); | |
| const makeKey = ([x1, y1]: Point, [x2, y2]: Point) => | |
| `(${x1},${y1}) -> (${x2},${y2})`; | |
| const splitKey = (key: string): [string, string] => | |
| key.split(" -> ") as [string, string]; | |
| function maxPointsOnLine(points: Point[]) { | |
| const slopes = new Map<string, number>(); |
OlderNewer