Add files via upload
9
Misc-Projects/guessing_game/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "guessing_game"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.5"
|
34
Misc-Projects/guessing_game/src/main.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use std::io;
|
||||
use std::cmp::Ordering;
|
||||
use rand::Rng;
|
||||
|
||||
|
||||
fn main() {
|
||||
println!("Guess the number!");
|
||||
|
||||
let secret_number = rand::thread_rng().gen_range(1..=100);
|
||||
|
||||
loop {
|
||||
|
||||
println!("Please input your guess.");
|
||||
|
||||
let mut guess = String::new();
|
||||
|
||||
io::stdin()
|
||||
.read_line(&mut guess)
|
||||
.expect("Failed to read line");
|
||||
|
||||
let guess: u32 = match guess.trim().parse() {
|
||||
Ok(num) => num,
|
||||
Err(_) => continue,
|
||||
};
|
||||
|
||||
println!("You guessed: {guess}");
|
||||
|
||||
match guess.cmp(&secret_number) {
|
||||
Ordering::Less => println!("Too small!"),
|
||||
Ordering::Greater => println!("Too big!"),
|
||||
Ordering::Equal => println!("You win"),
|
||||
}
|
||||
}
|
||||
}
|
9
Misc-Projects/hello_rainbow/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "hello_rainbow"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
termcolor = "1.2"
|
132
Misc-Projects/hello_rainbow/src/colors.rs
Normal file
@ -0,0 +1,132 @@
|
||||
use std::io::{Write};
|
||||
use termcolor::{Color, ColorChoice, ColorSpec, WriteColor, StandardStream};
|
||||
|
||||
pub fn print_green(text: &str) {
|
||||
// Create a color specification for green
|
||||
let mut spec = ColorSpec::new();
|
||||
spec.set_fg(Some(Color::Green));
|
||||
|
||||
// Create a standard stream for writing to the console
|
||||
let mut stdout = StandardStream::stdout(ColorChoice::Always);
|
||||
|
||||
// Write the text to the console with the green color
|
||||
stdout.set_color(&spec).unwrap();
|
||||
writeln!(&mut stdout, "{}", text).unwrap();
|
||||
|
||||
// Reset the color specification to the default
|
||||
stdout.reset().unwrap();
|
||||
}
|
||||
|
||||
pub fn print_black(text: &str) {
|
||||
// Create a color specification for black
|
||||
let mut spec = ColorSpec::new();
|
||||
spec.set_fg(Some(Color::Black));
|
||||
|
||||
// Create a standard stream for writing to the console
|
||||
let mut stdout = StandardStream::stdout(ColorChoice::Always);
|
||||
|
||||
// Write the text to the console with the green color
|
||||
stdout.set_color(&spec).unwrap();
|
||||
writeln!(&mut stdout, "{}", text).unwrap();
|
||||
|
||||
// Reset the color specification to the default
|
||||
stdout.reset().unwrap();
|
||||
}
|
||||
|
||||
pub fn print_blue(text: &str) {
|
||||
// Create a color specification for blue
|
||||
let mut spec = ColorSpec::new();
|
||||
spec.set_fg(Some(Color::Blue));
|
||||
|
||||
// Create a standard stream for writing to the console
|
||||
let mut stdout = StandardStream::stdout(ColorChoice::Always);
|
||||
|
||||
// Write the text to the console with the green color
|
||||
stdout.set_color(&spec).unwrap();
|
||||
writeln!(&mut stdout, "{}", text).unwrap();
|
||||
|
||||
// Reset the color specification to the default
|
||||
stdout.reset().unwrap();
|
||||
}
|
||||
|
||||
pub fn print_red(text: &str) {
|
||||
// Create a color specification for red
|
||||
let mut spec = ColorSpec::new();
|
||||
spec.set_fg(Some(Color::Red));
|
||||
|
||||
// Create a standard stream for writing to the console
|
||||
let mut stdout = StandardStream::stdout(ColorChoice::Always);
|
||||
|
||||
// Write the text to the console with the green color
|
||||
stdout.set_color(&spec).unwrap();
|
||||
writeln!(&mut stdout, "{}", text).unwrap();
|
||||
|
||||
// Reset the color specification to the default
|
||||
stdout.reset().unwrap();
|
||||
}
|
||||
|
||||
pub fn print_cyan(text: &str) {
|
||||
// Create a color specification for cyan
|
||||
let mut spec = ColorSpec::new();
|
||||
spec.set_fg(Some(Color::Cyan));
|
||||
|
||||
// Create a standard stream for writing to the console
|
||||
let mut stdout = StandardStream::stdout(ColorChoice::Always);
|
||||
|
||||
// Write the text to the console with the green color
|
||||
stdout.set_color(&spec).unwrap();
|
||||
writeln!(&mut stdout, "{}", text).unwrap();
|
||||
|
||||
// Reset the color specification to the default
|
||||
stdout.reset().unwrap();
|
||||
}
|
||||
|
||||
pub fn print_magenta(text: &str) {
|
||||
// Create a color specification for magenta
|
||||
let mut spec = ColorSpec::new();
|
||||
spec.set_fg(Some(Color::Magenta));
|
||||
|
||||
// Create a standard stream for writing to the console
|
||||
let mut stdout = StandardStream::stdout(ColorChoice::Always);
|
||||
|
||||
// Write the text to the console with the green color
|
||||
stdout.set_color(&spec).unwrap();
|
||||
writeln!(&mut stdout, "{}", text).unwrap();
|
||||
|
||||
// Reset the color specification to the default
|
||||
stdout.reset().unwrap();
|
||||
}
|
||||
|
||||
pub fn print_yellow(text: &str) {
|
||||
// Create a color specification for yellow
|
||||
let mut spec = ColorSpec::new();
|
||||
spec.set_fg(Some(Color::Yellow));
|
||||
|
||||
// Create a standard stream for writing to the console
|
||||
let mut stdout = StandardStream::stdout(ColorChoice::Always);
|
||||
|
||||
// Write the text to the console with the green color
|
||||
stdout.set_color(&spec).unwrap();
|
||||
writeln!(&mut stdout, "{}", text).unwrap();
|
||||
|
||||
// Reset the color specification to the default
|
||||
stdout.reset().unwrap();
|
||||
}
|
||||
|
||||
pub fn print_white(text: &str) {
|
||||
// Create a color specification for white
|
||||
let mut spec = ColorSpec::new();
|
||||
spec.set_fg(Some(Color::White));
|
||||
|
||||
// Create a standard stream for writing to the console
|
||||
let mut stdout = StandardStream::stdout(ColorChoice::Always);
|
||||
|
||||
// Write the text to the console with the green color
|
||||
stdout.set_color(&spec).unwrap();
|
||||
writeln!(&mut stdout, "{}", text).unwrap();
|
||||
|
||||
// Reset the color specification to the default
|
||||
stdout.reset().unwrap();
|
||||
}
|
||||
|
||||
|
14
Misc-Projects/hello_rainbow/src/main.rs
Normal file
@ -0,0 +1,14 @@
|
||||
mod colors;
|
||||
|
||||
fn main() {
|
||||
|
||||
colors::print_black("Hello Black!");
|
||||
colors::print_blue("Hello Blue!");
|
||||
colors::print_green("Hello Green!");
|
||||
colors::print_red("Hello Red!");
|
||||
colors::print_cyan("Hello Cyan!");
|
||||
colors::print_magenta("Hello Magenta!");
|
||||
colors::print_yellow("Hello Yellow!");
|
||||
colors::print_white("Hello White!");
|
||||
|
||||
}
|
75
Misc-Projects/password_generator/Cargo.lock
generated
Normal file
@ -0,0 +1,75 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.140"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
|
||||
|
||||
[[package]]
|
||||
name = "password_generator"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
9
Misc-Projects/password_generator/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "password_generator"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rand = "0.8.5"
|
19
Misc-Projects/password_generator/src/main.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use rand::Rng;
|
||||
|
||||
fn main() {
|
||||
|
||||
const CHARSET: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\
|
||||
abcdefghijklmnopqrstuvwxyz\
|
||||
0123456789)(*&^%$#@!~";
|
||||
const PASSWORD_LEN: usize = 30;
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let password: String = (0..PASSWORD_LEN)
|
||||
.map(|_| {
|
||||
let idx = rng.gen_range(0..CHARSET.len());
|
||||
CHARSET[idx] as char
|
||||
})
|
||||
.collect();
|
||||
println!("The following password was generated:");
|
||||
println!("{:?}", password);
|
||||
}
|
1114
Misc-Projects/random_quote/Cargo.lock
generated
Normal file
13
Misc-Projects/random_quote/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "random_quote"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
json = "0.12.4"
|
||||
serde_json = "1.0.94"
|
||||
reqwest = { version = "0.11", features = ["json", "blocking"] }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
serde = { version = "1.0.130", features = ["derive"] }
|
21
Misc-Projects/random_quote/src/main.rs
Normal file
@ -0,0 +1,21 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use reqwest::blocking::get;
|
||||
|
||||
pub type Response = Vec<Quote>;
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Quote {
|
||||
pub q: String,
|
||||
pub a: String,
|
||||
pub h: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let res = get("https://zenquotes.io/api/random").unwrap();
|
||||
let quotes = res.json::<Response>().unwrap();
|
||||
for quote in quotes {
|
||||
println!("Author: {}", quote.a);
|
||||
println!("Quote: {}", quote.q);
|
||||
}
|
||||
}
|
9
Misc-Projects/reverser/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "reverser"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.1.11", features = ["derive"] }
|
1
Misc-Projects/reverser/src/api/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod stringer;
|
20
Misc-Projects/reverser/src/api/stringer.rs
Normal file
@ -0,0 +1,20 @@
|
||||
pub fn reverse(input: &String) -> String {
|
||||
return input.chars().rev().collect();
|
||||
}
|
||||
|
||||
pub fn inspect(input: &String, digits: bool) -> (i32, String) {
|
||||
if !digits {
|
||||
return (input.len() as i32, String::from("char"));
|
||||
}
|
||||
return (inspect_numbers(input), String::from("digit"));
|
||||
}
|
||||
|
||||
fn inspect_numbers(input: &String) -> i32 {
|
||||
let mut count = 0;
|
||||
for c in input.chars() {
|
||||
if c.is_digit(10) {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
72
Misc-Projects/reverser/src/main.rs
Normal file
@ -0,0 +1,72 @@
|
||||
use ::clap::{Parser, Subcommand, Args};
|
||||
|
||||
mod api;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version)]
|
||||
#[command(about = "stringer - a simple CLI to reverse strings", long_about = "stringer is a simple, nimble cli for reversing and inspecting strings")]
|
||||
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
command: Option<Commands>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
|
||||
enum Commands {
|
||||
/// Reverses a string
|
||||
Reverse(Reverse),
|
||||
/// Inspects a string
|
||||
Inspect(Inspect),
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct Reverse {
|
||||
/// The string to reverse
|
||||
string: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct Inspect {
|
||||
/// The string to inspect
|
||||
string: Option<String>,
|
||||
|
||||
#[arg(short = 'd', long = "digits")]
|
||||
only_digits: bool,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
|
||||
match &cli.command {
|
||||
Some(Commands::Reverse(name)) => {
|
||||
match name.string {
|
||||
Some(ref _name) => {
|
||||
let reverse = api::stringer::reverse(_name);
|
||||
println!("{}", reverse);
|
||||
}
|
||||
None => {
|
||||
println!("Please provide a string to reverse");
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(Commands::Inspect(name)) => {
|
||||
match name.string {
|
||||
Some(ref _name) => {
|
||||
let (res, kind) = api::stringer::inspect(_name, name.only_digits);
|
||||
|
||||
let mut plural_s = "s";
|
||||
if res == 1 {
|
||||
plural_s = "";
|
||||
}
|
||||
|
||||
println!("{:?} has {} {}{}.", _name, res, kind, plural_s);
|
||||
}
|
||||
None => {
|
||||
println!("Please provide a string to inspect");
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
10
Misc-Projects/sha1_cracker/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "sha1_cracker"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
sha-1 = "0.10"
|
||||
hex = "0.4"
|
40
Misc-Projects/sha1_cracker/src/main.rs
Normal file
@ -0,0 +1,40 @@
|
||||
use sha1::Digest;
|
||||
use std::{
|
||||
env,
|
||||
error::Error,
|
||||
fs::File,
|
||||
io::{BufRead, BufReader},
|
||||
};
|
||||
|
||||
const SHA1_HEX_STRING_LENGTH: usize = 40;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
if args.len() != 3{
|
||||
println!("Usage:");
|
||||
println!("sha1_cracker: <wordlist.txt> <sha1_hash>");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let hash_to_crack = args[2].trim();
|
||||
if hash_to_crack.len() != SHA1_HEX_STRING_LENGTH {
|
||||
return Err("sha1 hash is not valid".into());
|
||||
}
|
||||
|
||||
let wordlist_file = File::open(&args[1])?;
|
||||
let reader = BufReader::new(&wordlist_file);
|
||||
|
||||
for line in reader.lines() {
|
||||
let line = line?;
|
||||
let common_password = line.trim();
|
||||
if hash_to_crack == &hex::encode(sha1::Sha1::digest(common_password.as_bytes())) {
|
||||
println!("Password found: {}", &common_password);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
println!("password not found in wordlist :(");
|
||||
|
||||
Ok(())
|
||||
}
|
2506
Misc-Projects/sha1_cracker/wordlist.txt
Normal file
11
Misc-Projects/states_parser/Cargo.toml
Normal file
@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "states"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
reqwest = { version = "0.11.6", features = ["blocking", "json"] }
|
||||
serde = { version = "1.0.130", features = ["derive"] }
|
||||
serde_json = "1.0.68"
|
31
Misc-Projects/states_parser/src/main.rs
Normal file
@ -0,0 +1,31 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct State {
|
||||
state: String,
|
||||
abbreviation: String,
|
||||
capital: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
let mut file = File::open("src/states.json").expect("File not found");
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents).expect("Unable to read file");
|
||||
let states: Vec<State> = serde_json::from_str(&contents).expect("Unable to parse JSON");
|
||||
|
||||
|
||||
let names: Vec<String> = states.iter().map(|s| s.state.clone()).collect();
|
||||
let abbreviations: Vec<String> = states.iter().map(|s| s.abbreviation.clone()).collect();
|
||||
let capitals: Vec<String> = states.iter().map(|s| s.capital.clone()).collect();
|
||||
|
||||
let mut i = 0;
|
||||
let len = names.len();
|
||||
|
||||
while i < len {
|
||||
println!("Name: {:?} | Abbreviation: {:?} | Capital: {:?}", names[i], abbreviations[i], capitals[i]);
|
||||
i = i+1;
|
||||
}
|
||||
}
|
298
Misc-Projects/states_parser/src/states.json
Normal file
@ -0,0 +1,298 @@
|
||||
[
|
||||
{
|
||||
"state": "Alabama",
|
||||
"abbreviation": "AL",
|
||||
"capital": "Montgomery"
|
||||
},
|
||||
{
|
||||
"state": "Alaska",
|
||||
"abbreviation": "AK",
|
||||
"capital": "Juneau"
|
||||
},
|
||||
{
|
||||
"state": "American Samoa",
|
||||
"abbreviation": "AS",
|
||||
"capital": "Pago Pago"
|
||||
},
|
||||
{
|
||||
"state": "Arizona",
|
||||
"abbreviation": "AZ",
|
||||
"capital": "Phoenix"
|
||||
},
|
||||
{
|
||||
"state": "Arkansas",
|
||||
"abbreviation": "AR",
|
||||
"capital": "Little Rock"
|
||||
},
|
||||
{
|
||||
"state": "California",
|
||||
"abbreviation": "CA",
|
||||
"capital": "Sacramento"
|
||||
},
|
||||
{
|
||||
"state": "Colorado",
|
||||
"abbreviation": "CO",
|
||||
"capital": "Denver"
|
||||
},
|
||||
{
|
||||
"state": "Connecticut",
|
||||
"abbreviation": "CT",
|
||||
"capital": "Hartford"
|
||||
},
|
||||
{
|
||||
"state": "Delaware",
|
||||
"abbreviation": "DE",
|
||||
"capital": "Dover"
|
||||
},
|
||||
{
|
||||
"state": "District of Columbia",
|
||||
"abbreviation": "DC",
|
||||
"capital": ""
|
||||
},
|
||||
{
|
||||
"state": "Federated States of Micronesia",
|
||||
"abbreviation": "FM",
|
||||
"capital": "Palikir"
|
||||
},
|
||||
{
|
||||
"state": "Florida",
|
||||
"abbreviation": "FL",
|
||||
"capital": "Tallahassee"
|
||||
},
|
||||
{
|
||||
"state": "Georgia",
|
||||
"abbreviation": "GA",
|
||||
"capital": "Atlanta"
|
||||
},
|
||||
{
|
||||
"state": "Guam",
|
||||
"abbreviation": "GU",
|
||||
"capital": "Hagåtña"
|
||||
},
|
||||
{
|
||||
"state": "Hawaii",
|
||||
"abbreviation": "HI",
|
||||
"capital": "Honolulu"
|
||||
},
|
||||
{
|
||||
"state": "Idaho",
|
||||
"abbreviation": "ID",
|
||||
"capital": "Boise"
|
||||
},
|
||||
{
|
||||
"state": "Illinois",
|
||||
"abbreviation": "IL",
|
||||
"capital": "Springfield"
|
||||
},
|
||||
{
|
||||
"state": "Indiana",
|
||||
"abbreviation": "IN",
|
||||
"capital": "Indianapolis"
|
||||
},
|
||||
{
|
||||
"state": "Iowa",
|
||||
"abbreviation": "IA",
|
||||
"capital": "Des Moines"
|
||||
},
|
||||
{
|
||||
"state": "Kansas",
|
||||
"abbreviation": "KS",
|
||||
"capital": "Topeka"
|
||||
},
|
||||
{
|
||||
"state": "Kentucky",
|
||||
"abbreviation": "KY",
|
||||
"capital": "Frankfort"
|
||||
},
|
||||
{
|
||||
"state": "Louisiana",
|
||||
"abbreviation": "LA",
|
||||
"capital": "Baton Rouge"
|
||||
},
|
||||
{
|
||||
"state": "Maine",
|
||||
"abbreviation": "ME",
|
||||
"capital": "Augusta"
|
||||
},
|
||||
{
|
||||
"state": "Marshall Islands",
|
||||
"abbreviation": "MH",
|
||||
"capital": "Majuro"
|
||||
},
|
||||
{
|
||||
"state": "Maryland",
|
||||
"abbreviation": "MD",
|
||||
"capital": "Annapolis"
|
||||
},
|
||||
{
|
||||
"state": "Massachusetts",
|
||||
"abbreviation": "MA",
|
||||
"capital": "Boston"
|
||||
},
|
||||
{
|
||||
"state": "Michigan",
|
||||
"abbreviation": "MI",
|
||||
"capital": "Lansing"
|
||||
},
|
||||
{
|
||||
"state": "Minnesota",
|
||||
"abbreviation": "MN",
|
||||
"capital": "Saint Paul"
|
||||
},
|
||||
{
|
||||
"state": "Mississippi",
|
||||
"abbreviation": "MS",
|
||||
"capital": "Jackson"
|
||||
},
|
||||
{
|
||||
"state": "Missouri",
|
||||
"abbreviation": "MO",
|
||||
"capital": "Jefferson City"
|
||||
},
|
||||
{
|
||||
"state": "Montana",
|
||||
"abbreviation": "MT",
|
||||
"capital": "Helena"
|
||||
},
|
||||
{
|
||||
"state": "Nebraska",
|
||||
"abbreviation": "NE",
|
||||
"capital": "Lincoln"
|
||||
},
|
||||
{
|
||||
"state": "Nevada",
|
||||
"abbreviation": "NV",
|
||||
"capital": "Carson City"
|
||||
},
|
||||
{
|
||||
"state": "New Hampshire",
|
||||
"abbreviation": "NH",
|
||||
"capital": "Concord"
|
||||
},
|
||||
{
|
||||
"state": "New Jersey",
|
||||
"abbreviation": "NJ",
|
||||
"capital": "Trenton"
|
||||
},
|
||||
{
|
||||
"state": "New Mexico",
|
||||
"abbreviation": "NM",
|
||||
"capital": "Santa Fe"
|
||||
},
|
||||
{
|
||||
"state": "New York",
|
||||
"abbreviation": "NY",
|
||||
"capital": "Albany"
|
||||
},
|
||||
{
|
||||
"state": "North Carolina",
|
||||
"abbreviation": "NC",
|
||||
"capital": "Raleigh"
|
||||
},
|
||||
{
|
||||
"state": "North Dakota",
|
||||
"abbreviation": "ND",
|
||||
"capital": "Bismarck"
|
||||
},
|
||||
{
|
||||
"state": "Northern Mariana Islands",
|
||||
"abbreviation": "MP",
|
||||
"capital": "Saipan"
|
||||
},
|
||||
{
|
||||
"state": "Ohio",
|
||||
"abbreviation": "OH",
|
||||
"capital": "Columbus"
|
||||
},
|
||||
{
|
||||
"state": "Oklahoma",
|
||||
"abbreviation": "OK",
|
||||
"capital": "Oklahoma City"
|
||||
},
|
||||
{
|
||||
"state": "Oregon",
|
||||
"abbreviation": "OR",
|
||||
"capital": "Salem"
|
||||
},
|
||||
{
|
||||
"state": "Palau",
|
||||
"abbreviation": "PW",
|
||||
"capital": "Ngerulmud"
|
||||
},
|
||||
{
|
||||
"state": "Pennsylvania",
|
||||
"abbreviation": "PA",
|
||||
"capital": "Harrisburg"
|
||||
},
|
||||
{
|
||||
"state": "Puerto Rico",
|
||||
"abbreviation": "PR",
|
||||
"capital": "San Juan"
|
||||
},
|
||||
{
|
||||
"state": "Rhode Island",
|
||||
"abbreviation": "RI",
|
||||
"capital": "Providence"
|
||||
},
|
||||
{
|
||||
"state": "South Carolina",
|
||||
"abbreviation": "SC",
|
||||
"capital": "Columbia"
|
||||
},
|
||||
{
|
||||
"state": "South Dakota",
|
||||
"abbreviation": "SD",
|
||||
"capital": "Pierre"
|
||||
},
|
||||
{
|
||||
"state": "Tennessee",
|
||||
"abbreviation": "TN",
|
||||
"capital": "Nashville"
|
||||
},
|
||||
{
|
||||
"state": "Texas",
|
||||
"abbreviation": "TX",
|
||||
"capital": "Austin"
|
||||
},
|
||||
{
|
||||
"state": "Utah",
|
||||
"abbreviation": "UT",
|
||||
"capital": "Salt Lake City"
|
||||
},
|
||||
{
|
||||
"state": "Vermont",
|
||||
"abbreviation": "VT",
|
||||
"capital": "Montpelier"
|
||||
},
|
||||
{
|
||||
"state": "Virgin Islands",
|
||||
"abbreviation": "VI",
|
||||
"capital": "Charlotte Amalie"
|
||||
},
|
||||
{
|
||||
"state": "Virginia",
|
||||
"abbreviation": "VA",
|
||||
"capital": "Richmond"
|
||||
},
|
||||
{
|
||||
"state": "Washington",
|
||||
"abbreviation": "WA",
|
||||
"capital": "Olympia"
|
||||
},
|
||||
{
|
||||
"state": "West Virginia",
|
||||
"abbreviation": "WV",
|
||||
"capital": "Charleston"
|
||||
},
|
||||
{
|
||||
"state": "Wisconsin",
|
||||
"abbreviation": "WI",
|
||||
"capital": "Madison"
|
||||
},
|
||||
{
|
||||
"state": "Wyoming",
|
||||
"abbreviation": "WY",
|
||||
"capital": "Cheyenne"
|
||||
}
|
||||
]
|
||||
|
19
Week-01/Day-01_Convert-Ages-To-Days/README.md
Normal file
@ -0,0 +1,19 @@
|
||||
## Convert Age to Days
|
||||
|
||||
Create a function that takes the age and return the age in days.
|
||||
|
||||
#### Examples
|
||||
|
||||
```text
|
||||
calcAge(65) ➞ 23725
|
||||
|
||||
calcAge(0) ➞ 0
|
||||
|
||||
calcAge(20) ➞ 7300
|
||||
```
|
||||
|
||||
### Notes
|
||||
|
||||
- Use 365 days as the length of a year for this challenge.
|
||||
- Ignore leap years and days between last birthday and now.
|
||||
- Expect only positive integer inputs.
|
24
Week-01/Day-02_Finding-Nemo/README.md
Normal file
@ -0,0 +1,24 @@
|
||||
## Finding Nemo
|
||||
|
||||
You're given a string of words. You need to find the word "Nemo", and return a string like this: `I found Nemo at [the order of the word you find nemo]!`.
|
||||
|
||||
If you can't find Nemo, return `I can't find Nemo :(`.
|
||||
|
||||
#### Examples
|
||||
|
||||
```text
|
||||
findNemo("I am finding Nemo !") ➞ "I found Nemo at 4!"
|
||||
|
||||
findNemo("Nemo is me") ➞ "I found Nemo at 1!"
|
||||
|
||||
findNemo("I Nemo am") ➞ "I found Nemo at 2!"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Notes
|
||||
|
||||
- `! , ? .` are always separated from the last word.
|
||||
- Nemo will always look like Nemo, and not NeMo or other capital variations.
|
||||
- Nemo's, or anything that says Nemo with something behind it, doesn't count as Finding Nemo.
|
||||
- If there are multiple Nemo's in the sentence, only return for the first one.
|
41
Week-01/Day-03_Barbecue-Skewers/README.md
Normal file
@ -0,0 +1,41 @@
|
||||
## Barbecue Skewers
|
||||
|
||||
You are in charge of the barbecue grill. A **vegetarian skewer** is a skewer that has **only vegetables (-o)**. A **non-vegetarian skewer** is a skewer with **at least one piece of meat (-x)**.
|
||||
|
||||
For example, the grill below has **4 non-vegetarian skewers** and **1 vegetarian skewer** (the one in the middle).
|
||||
|
||||
```text
|
||||
["--xo--x--ox--",
|
||||
"--xx--x--xx--",
|
||||
"--oo--o--oo--", <<< vegetarian skewer
|
||||
"--xx--x--ox--",
|
||||
"--xx--x--ox--"]
|
||||
```
|
||||
|
||||
#### Examples
|
||||
|
||||
Given a BBQ grill, write a function that returns `[# vegetarian skewers, # non-vegetarian skewers]`. For example above, the function should return `[1, 4]`.
|
||||
|
||||
```text
|
||||
[
|
||||
"--oooo-ooo--",
|
||||
"--xx--x--xx--",
|
||||
"--o---o--oo--",
|
||||
"--xx--x--ox--",
|
||||
"--xx--x--ox--"
|
||||
] ➞ [2, 3]
|
||||
|
||||
[
|
||||
"--oooo-ooo--",
|
||||
"--xxxxxxxx--",
|
||||
"--o---",
|
||||
"-o-----o---x--",
|
||||
"--o---o-----"
|
||||
) ➞ [3, 2]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Notes
|
||||
|
||||
- NA
|
24
Week-01/Day-04_Is-Johnny-Making-Progress/README.md
Normal file
@ -0,0 +1,24 @@
|
||||
## Is Johnny Making Progress?
|
||||
|
||||
To train for an upcoming marathon, Johnny goes on one long-distance run each Saturday. He wants to track how often the number of miles he runs this Saturday exceeds the number of miles run the **previous** Saturday. This is called a **progress day**.
|
||||
|
||||
Create a function that takes in an array of miles run every Saturday and returns Johnny's total number of progress days.
|
||||
|
||||
### Examples
|
||||
|
||||
```text
|
||||
progressDays([3, 4, 1, 2]) ➞ 2
|
||||
// There are two progress days, (3->4) and (1->2)
|
||||
|
||||
progressDays([10, 11, 12, 9, 10]) ➞ 3
|
||||
|
||||
progressDays([6, 5, 4, 3, 2, 9]) ➞ 1
|
||||
|
||||
progressDays([9, 9]) ➞ 0
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Notes
|
||||
|
||||
- Running the **same number of miles** as last week does not count as a progress day.
|
22
Week-01/Day-05_Pair-Of-Socks/README.md
Normal file
@ -0,0 +1,22 @@
|
||||
## Pair of Socks
|
||||
|
||||
Joseph is in the middle of packing for a vacation. He's having a bit of trouble finding all of his socks, though.
|
||||
|
||||
Write a function that returns the number of sock pairs he has. A sock pair consists of two of the same letter, such as `"AA"`. The socks are represented as an unordered sequence.
|
||||
|
||||
### Examples
|
||||
|
||||
```text
|
||||
SockPairs("AA") ➞ 1
|
||||
|
||||
SockPairs("ABABC") ➞ 2
|
||||
|
||||
SockPairs("CABBACCC") ➞ 4
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Notes
|
||||
|
||||
- If given an empty string (no socks in the drawer), return 0.
|
||||
- There can be multiple pairs of the same type of sock, such as two pairs of CC for the last example.
|
20
Week-01/Day-06_Next-Prime/README.md
Normal file
@ -0,0 +1,20 @@
|
||||
## Next Prime
|
||||
|
||||
Given an integer, create a function that returns the next prime. If the number is prime, return the number itself.
|
||||
|
||||
### Examples
|
||||
|
||||
```text
|
||||
NextPrime(12) ➞ 13
|
||||
|
||||
NextPrime(24) ➞ 29
|
||||
|
||||
NextPrime(11) ➞ 11
|
||||
// 11 is a prime, so we return the number itself.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Notes
|
||||
|
||||
- N/A
|
26
Week-01/Day-07_Merge-Sorted-Array/README.md
Normal file
@ -0,0 +1,26 @@
|
||||
## Merge Sorted Array
|
||||
|
||||
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
|
||||
|
||||
### Examples
|
||||
|
||||
```text
|
||||
Input:
|
||||
nums1 = [1,2,3,0,0,0], m = 3
|
||||
nums2 = [2,5,6], n = 3
|
||||
|
||||
Output: [1,2,2,3,5,6]
|
||||
```
|
||||
|
||||
### Constraints
|
||||
|
||||
- `-10^9 <= nums1[i], nums2[i] <= 10^9`
|
||||
- `nums1.length == m + n`
|
||||
- `nums2.length == n`
|
||||
|
||||
---
|
||||
|
||||
### Notes
|
||||
|
||||
- The number of elements initialized in nums1 and nums2 are m and n respectively.
|
||||
- You may assume that nums1 has enough space (size that is **equal** to m + n) to hold additional elements from nums2.
|
@ -0,0 +1,43 @@
|
||||
## Letter Combinations of a Phone Number
|
||||
|
||||
Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in **any order**.
|
||||
|
||||
A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
|
||||
|
||||
<p align="left">
|
||||
<img src="../../assets/Telephone-keypad2.png" alt="telefone keypad">
|
||||
</p>
|
||||
|
||||
### Examples
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```text
|
||||
Input: digits = "23"
|
||||
Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```text
|
||||
Input: digits = ""
|
||||
Output: []
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```text
|
||||
Input: digits = "2"
|
||||
Output: ["a","b","c"]
|
||||
```
|
||||
|
||||
### Constraints
|
||||
|
||||
- `0 <= digits.length <= 4`
|
||||
- `digits[i] is a digit in the range ['2', '9'].`
|
||||
|
||||
---
|
||||
|
||||
### Notes
|
||||
|
||||
- N/A
|
36
Week-02/Day-09_Trapping-Rain-Water/README.md
Normal file
@ -0,0 +1,36 @@
|
||||
## Trapping Rain Water
|
||||
|
||||
Given `n` non-negative integers representing an elevation map where the width of each bar is `1`, compute how much water it can trap after raining.
|
||||
|
||||
### Examples
|
||||
|
||||
**Example 1:**
|
||||
|
||||
<p align="left">
|
||||
<img src="../../assets/rainwatertrap.png" alt="Rain water trap">
|
||||
</p>
|
||||
|
||||
```text
|
||||
Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]
|
||||
Output: 6
|
||||
Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```text
|
||||
Input: height = [4,2,0,3,2,5]
|
||||
Output: 9
|
||||
```
|
||||
|
||||
### Constraints
|
||||
|
||||
- `n == height.length`
|
||||
- `0 <= n <= 3 * 104`
|
||||
- `0 <= height[i] <= 105`
|
||||
|
||||
---
|
||||
|
||||
### Notes
|
||||
|
||||
- N/A
|
28
Week-02/Day-10_Unique-Binary-Search-Trees/README.md
Normal file
@ -0,0 +1,28 @@
|
||||
## Unique Binary Search Trees
|
||||
|
||||
Given `n`, how many structurally unique **BST's** (binary search trees) that store values 1 ... `n`?
|
||||
|
||||
### Examples
|
||||
|
||||
```text
|
||||
Input: 3
|
||||
Output: 5
|
||||
Explanation:
|
||||
Given n = 3, there are a total of 5 unique BST's:
|
||||
|
||||
1 3 3 2 1
|
||||
\ / / / \ \
|
||||
3 2 1 1 3 2
|
||||
/ / \ \
|
||||
2 1 2 3
|
||||
```
|
||||
|
||||
### Constraints
|
||||
|
||||
- `1 <= n <= 19`
|
||||
|
||||
---
|
||||
|
||||
### Notes
|
||||
|
||||
- N/A
|
54
Week-02/Day-11_Restore-IP-Addresses/README.md
Normal file
@ -0,0 +1,54 @@
|
||||
## Restore IP Addresses
|
||||
|
||||
Given a string s containing only digits, return all possible valid IP addresses that can be obtained from s. You can return them in **any** order.
|
||||
|
||||
A **valid IP address** consists of exactly four integers, each integer is between 0 and 255, separated by single dots and cannot have leading zeros. For example, "0.1.2.201" and "192.168.1.1" are **valid** IP addresses and "0.011.255.245", "192.168.1.312" and "192.168@1.1" are **invalid** IP addresses.
|
||||
|
||||
### Examples
|
||||
|
||||
**Example 1:**
|
||||
|
||||
```text
|
||||
Input: s = "25525511135"
|
||||
Output: ["255.255.11.135","255.255.111.35"]
|
||||
```
|
||||
|
||||
**Example 2:**
|
||||
|
||||
```text
|
||||
Input: s = "0000"
|
||||
Output: ["0.0.0.0"]
|
||||
```
|
||||
|
||||
**Example 3:**
|
||||
|
||||
```text
|
||||
Input: s = "1111"
|
||||
Output: ["1.1.1.1"]
|
||||
```
|
||||
|
||||
**Example 4:**
|
||||
|
||||
```text
|
||||
Input: s = "010010"
|
||||
Output: ["0.10.0.10","0.100.1.0"]
|
||||
```
|
||||
|
||||
**Example 5:**
|
||||
|
||||
```text
|
||||
Input: s = "101023"
|
||||
Output: ["1.0.10.23","1.0.102.3","10.1.0.23","10.10.2.3","101.0.2.3"]
|
||||
```
|
||||
|
||||
### Constraints
|
||||
|
||||
- `0 <= s.length`
|
||||
- `s consists of digits only.`
|
||||
- `Ipv4 format only.`
|
||||
|
||||
---
|
||||
|
||||
### Notes
|
||||
|
||||
- `All digits in string s MUST be used to obtain each valid IP`
|
53
Week-02/Day-12_Mountains_And_Valleys/README.md
Normal file
@ -0,0 +1,53 @@
|
||||
## Mountains or Valleys
|
||||
|
||||
A mountain is an array with **exactly one peak.**
|
||||
|
||||
- All numbers to the left of the **peak** are increasing.
|
||||
- All numbers to the right of the **peak** are decreasing.
|
||||
- The peak CANNOT be on the boundary.
|
||||
|
||||
A valley is an array with **exactly one trough**.
|
||||
|
||||
- All numbers to the left of the **trough** are decreasing.
|
||||
- All numbers to the right of the **trough** are increasing.
|
||||
- The trough CANNOT be on the boundary.
|
||||
|
||||
### Some examples of **mountains** and **valleys**:
|
||||
|
||||
```text
|
||||
Mountain A: [1, 3, 5, 4, 3, 2] // 5 is the peak
|
||||
Mountain B: [-1, 0, -1] // 0 is the peak
|
||||
Mountain B: [-1, -1, 0, -1, -1] // 0 is the peak (plateau on both sides is okay)
|
||||
|
||||
Valley A: [10, 9, 8, 7, 2, 3, 4, 5] // 2 is the trough
|
||||
Valley B: [350, 100, 200, 400, 700] // 100 is the trough
|
||||
```
|
||||
|
||||
Neither **mountains** nor **valleys**:
|
||||
|
||||
```text
|
||||
Landscape A: [1, 2, 3, 2, 4, 1] // 2 peaks (3, 4), not 1
|
||||
Landscape B: [5, 4, 3, 2, 1] // Peak cannot be a boundary element
|
||||
Landscape B: [0, -1, -1, 0, -1, -1] // 2 peaks (0)
|
||||
```
|
||||
|
||||
Based on the rules above, write a function that takes in an array and returns either `"mountain"`, `"valley"`, or `"neither"`.
|
||||
|
||||
### Examples
|
||||
|
||||
```text
|
||||
LandscapeType([3, 4, 5, 4, 3]) ➞ "mountain"
|
||||
|
||||
LandscapeType([9, 7, 3, 1, 2, 4]) ➞ "valley"
|
||||
|
||||
LandscapeType([9, 8, 9]) ➞ "valley"
|
||||
|
||||
LandscapeType([9, 8, 9, 8]) ➞ "neither"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Notes
|
||||
|
||||
- A peak is not exactly the same as the **max** of an array. The **max** is a unique number, but an array may have multiple peaks. However, if there exists only one peak in an array, then it is true that the peak = max.
|
||||
- See comments for a hint.
|
32
Week-02/Day-13_Need-Help-With-Packing/README.md
Normal file
@ -0,0 +1,32 @@
|
||||
## Need Help With Your Packing?
|
||||
|
||||
You arrive at the supermarket checkout and you've only got a limited number of shopping bags with you. Miser that you are, you hate buying extra bags when you've got dozens at home that you forgot to bring with you!! Can you fit all your shopping into the bags you've got with you?
|
||||
|
||||
Each bag can carry a maximum of 10kg and each item you've purchased weighs between 1 and 10kg.
|
||||
|
||||
Create a function that takes two parameters, a list of the weights of each item and the number of bags you are carrying. Return `True` if there are enough bags to contain all the items, otherwise `False`.
|
||||
|
||||
### Example
|
||||
|
||||
```text
|
||||
CanFit(new int[] { 2, 1, 2, 5, 4, 3, 6, 1, 1, 9, 3, 2 }, 4) ➞ True
|
||||
// Bag 1 = [2, 1, 2, 5] (10kg)
|
||||
// Bag 2 = [4, 3, 3] (10kg)
|
||||
// Bag 3 = [6, 2, 1, 1] (10kg)
|
||||
// Bag 4 = [9] (9kg)
|
||||
|
||||
CanFit(new int[] { 2, 7, 1, 3, 3, 4, 7, 4, 1, 8, 2 ], 4) ➞ False
|
||||
// Bag 1 = [2, 8] (10kg)
|
||||
// Bag 2 = [3, 7] (10kg)
|
||||
// Bag 3 = [2, 4, 4] (10kg)
|
||||
// Bag 4 = [7, 3] (10kg)
|
||||
// two 1kg items left over!
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Notes
|
||||
|
||||
- All weights will be integers between 1 and 10kg inclusive
|
||||
- Items can be packed in any order
|
||||
- There may be more than one way to fit all the items in the available bags
|
41
Week-02/Day-14_Karacas-Encryption-Algorithm/README.md
Normal file
@ -0,0 +1,41 @@
|
||||
## The Karaca's Encryption Algorithm
|
||||
|
||||
Make a function that encrypts a given input with these steps:
|
||||
|
||||
Input: `"apple"`
|
||||
|
||||
Step 1: Reverse the input: `"elppa"`
|
||||
|
||||
Step 2: Replace all vowels using the following chart:
|
||||
|
||||
```text
|
||||
a => 0
|
||||
e => 1
|
||||
i => 2
|
||||
o => 2
|
||||
u => 3
|
||||
|
||||
// "1lpp0"
|
||||
```
|
||||
|
||||
Step 3: Add "aca" to the end of the word: `"1lpp0aca"`
|
||||
|
||||
Output: `"1lpp0aca"`
|
||||
|
||||
### Example
|
||||
|
||||
```text
|
||||
Encrypt("banana") ➞ "0n0n0baca"
|
||||
|
||||
Encrypt("karaca") ➞ "0c0r0kaca"
|
||||
|
||||
Encrypt("burak") ➞ "k0r3baca"
|
||||
|
||||
Encrypt("alpaca") ➞ "0c0pl0aca"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Notes
|
||||
|
||||
- All inputs are strings, no uppercases and all output must be strings.
|
25
Week-03/Day-15_Valid-Anagram/README.md
Normal file
@ -0,0 +1,25 @@
|
||||
## Valid Anagram
|
||||
|
||||
Given two strings s and t , write a function to determine if t is an anagram of s.
|
||||
|
||||
### Examples
|
||||
|
||||
**Example 1**
|
||||
|
||||
```text
|
||||
Input: s = "anagram", t = "nagaram"
|
||||
Output: true
|
||||
```
|
||||
|
||||
**Example 2**
|
||||
|
||||
```text
|
||||
Input: s = "rat", t = "car"
|
||||
Output: false
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Notes
|
||||
|
||||
- You may assume the string contains only lowercase alphabets.
|
43
Week-03/Day-16_Nim-Game/README.md
Normal file
@ -0,0 +1,43 @@
|
||||
## Nim Game
|
||||
|
||||
You are playing the following Nim Game with your friend:
|
||||
|
||||
- Initially, there is a heap of stones on the table.
|
||||
- You and your friend will alternate taking turns, and **you go first**.
|
||||
- On each turn, the person whose turn it is will remove 1 to 3 stones from the heap.
|
||||
- The one who removes the last stone is the winner.
|
||||
- Given `n`, the number of stones in the heap, return `true` if you can win the game assuming both you and your friend play optimally, otherwise return `false`.
|
||||
|
||||
### Examples
|
||||
|
||||
**Example 1**
|
||||
|
||||
```text
|
||||
Input: n = 4
|
||||
Output: false
|
||||
Explanation: These are the possible outcomes:
|
||||
1. You remove 1 stone. Your friend removes 3 stones, including the last stone. Your friend wins.
|
||||
2. You remove 2 stones. Your friend removes 2 stones, including the last stone. Your friend wins.
|
||||
3. You remove 3 stones. Your friend removes the last stone. Your friend wins.
|
||||
In all outcomes, your friend wins.
|
||||
```
|
||||
|
||||
**Example 2**
|
||||
|
||||
```text
|
||||
Input: n = 1
|
||||
Output: true
|
||||
```
|
||||
|
||||
**Example 3**
|
||||
|
||||
```text
|
||||
Input: n = 2
|
||||
Output: true
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Constraints
|
||||
|
||||
- `1 <= n <= 231 - 1`
|
51
Week-03/Day-17_Prison-Break/README.md
Normal file
@ -0,0 +1,51 @@
|
||||
## Prison Break
|
||||
|
||||
A prison can be represented as an array of cells. Each cell contains exactly one prisoner. A `1` represents an unlocked cell and a `0` represents a locked cell.
|
||||
|
||||
```
|
||||
[1, 1, 0, 0, 0, 1, 0]
|
||||
```
|
||||
|
||||
Starting inside the leftmost cell, you are tasked with seeing how many prisoners you can set free, with a catch. You are the prisoner in the first cell. If the first cell is locked, you cannot free anyone. Each time you free a prisoner, the locked cells become unlocked, and the unlocked cells become locked again.
|
||||
|
||||
So, if we use the example above:
|
||||
|
||||
```
|
||||
[1, 1, 0, 0, 0, 1, 0]
|
||||
// You free the prisoner in the 1st cell.
|
||||
|
||||
[0, 0, 1, 1, 1, 0, 1]
|
||||
// You free the prisoner in the 3rd cell (2nd one locked).
|
||||
|
||||
[1, 1, 0, 0, 0, 1, 0]
|
||||
// You free the prisoner in the 6th cell (3rd, 4th, and 5th locked).
|
||||
|
||||
[0, 0, 1, 1, 1, 0, 1]
|
||||
// You free the prisoner in the 7th cell - and you are done!
|
||||
```
|
||||
|
||||
Here, we have set free `4` prisoners in total.
|
||||
|
||||
Create a function that, given this unique prison arrangement, returns the number of freed prisoners.
|
||||
|
||||
### Examples
|
||||
|
||||
**Example 1**
|
||||
|
||||
```text
|
||||
freedPrisoners([1, 1, 0, 0, 0, 1, 0]) ➞ 4
|
||||
|
||||
freedPrisoners([1, 1, 1]) ➞ 1
|
||||
|
||||
freedPrisoners([0, 0, 0]) ➞ 0
|
||||
|
||||
freedPrisoners([0, 1, 1, 1]) ➞ 0
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Notes
|
||||
|
||||
- You are the prisoner in the first cell. You must be freed to free anyone else.
|
||||
- You must free a prisoner in order for the locks to switch. So in the second example where the input is `[1, 1, 1]` after you release the first prisoner, the locks change to `[0, 0, 0]`. Since all cells are locked, you can release no more prisoners.
|
||||
- You always start with the leftmost element in the array (the first prison cell). If all the prison cells to your right are all zeroes, you cannot free any more prisoners.
|
53
Week-03/Day-18_Unique-Paths/README.md
Normal file
@ -0,0 +1,53 @@
|
||||
## Unique Paths
|
||||
|
||||
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
|
||||
|
||||
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
|
||||
|
||||
How many possible unique paths are there?
|
||||
|
||||
### Examples
|
||||
|
||||
**Example 1**
|
||||
|
||||
<p align="left">
|
||||
<img src="../../assets/robot_maze.png" alt="Robot Maze">
|
||||
</p>
|
||||
|
||||
```text
|
||||
Input: m = 3, n = 7
|
||||
Output: 28
|
||||
```
|
||||
|
||||
**Example 2**
|
||||
|
||||
```text
|
||||
Input: m = 3, n = 2
|
||||
Output: 3
|
||||
Explanation:
|
||||
From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
|
||||
1. Right -> Down -> Down
|
||||
2. Down -> Down -> Right
|
||||
3. Down -> Right -> Down
|
||||
```
|
||||
|
||||
**Example 3**
|
||||
|
||||
```text
|
||||
Input: m = 7, n = 3
|
||||
Output: 28
|
||||
```
|
||||
|
||||
**Example 4**
|
||||
|
||||
```text
|
||||
Input: m = 3, n = 3
|
||||
Output: 6
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Constraints
|
||||
|
||||
- `1 <= m, n <= 100`
|
||||
- It's guaranteed that the answer will be less than or equal to `2 * 109`.
|
17
Week-03/Day-19_URL-Shortener/README.md
Normal file
@ -0,0 +1,17 @@
|
||||
## URL Shortener
|
||||
|
||||
URL shortening is used to create shorter aliases for long URLs. We call these shortened aliases “short links.” Users are redirected to the original URL when they hit these short links. Short links save a lot of space when displayed, printed, messaged, or tweeted. Additionally, users are less likely to mistype shorter URLs. URL shortening is used to optimize links across devices, track individual links to analyze audience, measure ad campaigns’ performance, or hide affiliated original URLs.
|
||||
|
||||
<p align="left">
|
||||
<img src="../../assets/url_shortener.png" alt="Rain water trap">
|
||||
</p>
|
||||
|
||||
---
|
||||
|
||||
### Constraints
|
||||
|
||||
- Given a URL, our service should generate a shorter and unique alias of it. This is called a short link. This link should be short enough to be easily copied and pasted into applications.
|
||||
- Users should optionally be able to pick a custom short link for their URL.
|
||||
- URL format must be validated
|
||||
- URL < 200 characters
|
||||
- Shortened links should not be guessable (not predictable).
|
68
Week-03/Day-20_API-Challenge/README.md
Normal file
@ -0,0 +1,68 @@
|
||||
# API Challenge
|
||||
|
||||
## Requirements
|
||||
|
||||
Design an API endpoint that provides autocomplete suggestions for large cities.
|
||||
The suggestions should be restricted to cities in the USA, Brazil and Canada with a population above 5000 people.
|
||||
|
||||
- the endpoint is exposed at `/suggestions`
|
||||
- the partial (or complete) search term is passed as a query string parameter `q`
|
||||
- the caller's location can optionally be supplied via query string parameters `latitude` and `longitude` to help improve relative scores
|
||||
- the endpoint returns a JSON response with an array of scored suggested matches
|
||||
- the suggestions are sorted by descending score
|
||||
- each suggestion has a score between 0 and 1 (inclusive) indicating confidence in the suggestion (1 is most confident)
|
||||
- each suggestion has a name which can be used to disambiguate between similarly named locations
|
||||
- each suggestion has a latitude and longitude
|
||||
|
||||
#### Sample responses
|
||||
|
||||
These responses are meant to provide guidance. The exact values can vary based on the data source and scoring algorithm.
|
||||
|
||||
**Near match**
|
||||
|
||||
GET /suggestions?q=Londo&latitude=43.70011&longitude=-79.4163
|
||||
|
||||
```json
|
||||
{
|
||||
"suggestions": [
|
||||
{
|
||||
"name": "London, ON, Canada",
|
||||
"latitude": "42.98339",
|
||||
"longitude": "-81.23304",
|
||||
"score": 0.9
|
||||
},
|
||||
{
|
||||
"name": "London, OH, USA",
|
||||
"latitude": "39.88645",
|
||||
"longitude": "-83.44825",
|
||||
"score": 0.5
|
||||
},
|
||||
{
|
||||
"name": "London, KY, USA",
|
||||
"latitude": "37.12898",
|
||||
"longitude": "-84.08326",
|
||||
"score": 0.5
|
||||
},
|
||||
{
|
||||
"name": "Londontowne, MD, USA",
|
||||
"latitude": "38.93345",
|
||||
"longitude": "-76.54941",
|
||||
"score": 0.3
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
**No match**
|
||||
|
||||
GET /suggestions?q=SomeRandomCityInTheMiddleOfNowhere
|
||||
|
||||
```json
|
||||
{
|
||||
"suggestions": []
|
||||
}
|
||||
```
|
||||
|
||||
## Datasource
|
||||
|
||||
You can use [Google Geolocation](https://www.googleadservices.com/pagead/aclk?sa=L&ai=DChcSEwiH3ojJ-NrsAhUHt3cKHdWuC0QYABAAGgJlZg&ohost=www.google.com&cid=CAESP-D2vI6oOFB6UkonTsUenG2N8-pZmAiypdXPRE2lSiBXlM1-4706UwapRywBQ96FXr7_rMpRkyIqSmPAvSoWQQ&sig=AOD64_3q0rlOPwXTglNovTTowHbzbFfr6A&q&adurl&ved=2ahUKEwj_z4DJ-NrsAhUHNOwKHcWkBRYQ0Qx6BAgPEAE) API or any other API you'd like
|
39
Week-03/Day-21_Random-Maze-Generator/README.md
Normal file
@ -0,0 +1,39 @@
|
||||
## Random Maze Generator
|
||||
|
||||
A maze can be generated by starting with a predetermined arrangement of cells with wall sites between them. This predetermined arrangement can be considered as a connected graph with the edges representing possible wall sites and the nodes representing cells. The purpose of the maze generation algorithm can then be considered to be making a sub-graph in which it is challenging to find a route between two particular nodes.
|
||||
|
||||
Given an input, generate a random Maze.
|
||||
|
||||
### Examples
|
||||
|
||||
**Example 1**
|
||||
|
||||
```text
|
||||
DrawMaze(5,7)
|
||||
```
|
||||
|
||||
**Output**
|
||||
|
||||
<p align="left">
|
||||
<img src="../../assets/maze.png" alt="Maze">
|
||||
</p>
|
||||
|
||||
**Example 2**
|
||||
|
||||
```text
|
||||
DrawMaze(4,6)
|
||||
```
|
||||
|
||||
**Output**
|
||||
|
||||
```text
|
||||
+---+---+---+---+---+---+
|
||||
| | | |
|
||||
+ + + +---+ +---+
|
||||
| | | | |
|
||||
+ + +---+---+---+ +
|
||||
| | | |
|
||||
+ + + +---+---+ +
|
||||
| | |
|
||||
+---+---+---+---+---+---+
|
||||
```
|
21
Week-04/Day-22_Marcio-Mellos-Challenge/README.md
Normal file
@ -0,0 +1,21 @@
|
||||
## Marcio Mello's Challenge
|
||||
|
||||
The deforested are of the Amazon rain Forest was 9,762 km² between August 2018 and July 2019, according to official figures from the federal government Inpe (National Institute for Space Research).
|
||||
This is an increase of 29.5% over the previous period (August 2017 to July 2018), which recorded 7,536 km² of deforested area. The proeminent brazilian matematician **Marcio Mello**, calculated the deforest area in football fields to make it easier to regular people to understand how big is the damage of the current government to the environment.
|
||||
Taking him as an example, create an algorithm that given a deforested area (in km2) it returns the correspondent amount of football fields.
|
||||
|
||||
<p align="left">
|
||||
<img src="../../assets/amazon_deforestation.jpg" alt="Amazon Forest Burning">
|
||||
</p>
|
||||
|
||||
## Examples
|
||||
|
||||
```text
|
||||
input: 1.034
|
||||
|
||||
result: 100.000 football fields
|
||||
```
|
||||
|
||||
## Constraints
|
||||
|
||||
- Fifa standard football field: `105m x 68m`
|
43
Week-04/Day-23_The-Dining_Philosophers/README.md
Normal file
@ -0,0 +1,43 @@
|
||||
## The Dining Philosophers
|
||||
|
||||
Five silent philosophers sit at a round table with bowls of spaghetti. Forks are placed between each pair of adjacent philosophers.
|
||||
|
||||
Each philosopher must alternately think and eat. However, a philosopher can only eat spaghetti when they have both left and right forks. Each fork can be held by only one philosopher and so a philosopher can use the fork only if it is not being used by another philosopher. After an individual philosopher finishes eating, they need to put down both forks so that the forks become available to others. A philosopher can take the fork on their right or the one on their left as they become available, but cannot start eating before getting both forks.
|
||||
|
||||
Eating is not limited by the remaining amounts of spaghetti or stomach space; an infinite supply and an infinite demand are assumed.
|
||||
|
||||
Design a discipline of behaviour (a concurrent algorithm) such that no philosopher will starve; i.e., each can forever continue to alternate between eating and thinking, assuming that no philosopher can know when others may want to eat or think.
|
||||
|
||||
<p align="left">
|
||||
<img src="../../assets/dining_philosophers_problem.png" width=400 height=400 alt="Dining Philosophers">
|
||||
</p>
|
||||
|
||||
The philosophers' ids are numbered from **0** to **4** in a **clockwise** order. Implement the function void wantsToEat(philosopher, pickLeftFork, pickRightFork, eat, putLeftFork, putRightFork) where:
|
||||
|
||||
- `philosopher` is the id of the philosopher who wants to eat.
|
||||
- `pickLeftFork` and `pickRightFork` are functions you can call to pick the corresponding forks of that philosopher.
|
||||
- `eat` is a function you can call to let the philosopher eat once he has picked both forks.
|
||||
- `putLeftFork` and `putRightFork` are functions you can call to put down the corresponding forks of that philosopher.
|
||||
- The philosophers are assumed to be thinking as long as they are not asking to eat (the function is not being called with their number).
|
||||
|
||||
Five threads, each representing a philosopher, will simultaneously use one object of your class to simulate the process. The function may be called for the same philosopher more than once, even before the last call ends.
|
||||
|
||||
### Example
|
||||
|
||||
```text
|
||||
Input: n = 1
|
||||
Output: [[4,2,1],[4,1,1],[0,1,1],[2,2,1],[2,1,1],[2,0,3],[2,1,2],[2,2,2],[4,0,3],[4,1,2],[0,2,1],[4,2,2],[3,2,1],[3,1,1],[0,0,3],[0,1,2],[0,2,2],[1,2,1],[1,1,1],[3,0,3],[3,1,2],[3,2,2],[1,0,3],[1,1,2],[1,2,2]]
|
||||
|
||||
Explanation:
|
||||
n is the number of times each philosopher will call the function.
|
||||
The output array describes the calls you made to the functions controlling the forks and the eat function, its format is:
|
||||
output[i] = [a, b, c] (three integers)
|
||||
|
||||
- a is the id of a philosopher.
|
||||
- b specifies the fork: {1 : left, 2 : right}.
|
||||
- c specifies the operation: {1 : pick, 2 : put, 3 : eat}.
|
||||
```
|
||||
|
||||
### Constraints
|
||||
|
||||
- `1 <= n <= 60`
|
26
Week-04/Day-24_The-Josephus-Problem/README.md
Normal file
@ -0,0 +1,26 @@
|
||||
## The Josephus Problem
|
||||
|
||||
This classic problem dates back to Roman times. There are 41 soldiers arranged in a circle. Every third soldier is to be killed by their captors, continuing around the circle until only one soldier remains. He is to be freed. Assuming you would like to stay alive, at what position in the circle would you stand?
|
||||
|
||||
Generalize this problem by creating a function that accepts the number of soldiers `n` and the interval at which they are killed `i`, and returns the position of the fortunate survivor.
|
||||
|
||||
<p align="left">
|
||||
<img src="../../assets/josephus-problem.jpg" alt="Josephus Problem">
|
||||
</p>
|
||||
|
||||
### Example
|
||||
|
||||
```text
|
||||
josephus(41, 3) ➞ 31
|
||||
|
||||
josephus(35, 11) ➞ 18
|
||||
|
||||
josephus(11, 1) ➞ 11
|
||||
|
||||
josephus(2, 2) ➞ 1
|
||||
```
|
||||
|
||||
### Notes
|
||||
|
||||
- Assume the positions are numbered 1 to `n` going **clockwise** around the circle.
|
||||
- If the interval is 3, the first soldiers to die are at positions 3, 6, and 9.
|
32
Week-04/Day-25_Coin-Trouble/README.md
Normal file
@ -0,0 +1,32 @@
|
||||
## Coin Trouble
|
||||
|
||||
Given an array of coins, father needs to distribute them amongst his three children. Write a function to determine if the coins can be distributed equally or not. Return `true` if each son receives the same amount of money, otherwise return `false`.
|
||||
|
||||
```
|
||||
[1, 2, 3, 2, 2, 2, 3] ➞ true
|
||||
```
|
||||
|
||||
- Amount to be distributed to each child = `(1+2+3+2+4+3)/3 => 15/3 => 5`
|
||||
- Possible set of coin to be distributed to children = `[(1,2,2),(2,3),(2,3)]`
|
||||
|
||||
```
|
||||
[5, 3, 10, 1, 2] ➞ false
|
||||
```
|
||||
|
||||
- Amount to be distributed to each child = `(5+3+10+1+2)/3 => 21/3 => 7`
|
||||
- But there are no combination such that each child get equal value which is `7`.
|
||||
|
||||
### Example
|
||||
|
||||
```text
|
||||
coinsDiv([1, 2, 3, 2, 2, 2, 3]) ➞ true
|
||||
|
||||
coinsDiv([5, 3, 10, 1, 2]) ➞ false
|
||||
|
||||
coinsDiv([2, 4, 3, 2, 4, 9, 7, 8, 6, 9]) ➞ true
|
||||
```
|
||||
|
||||
### Notes
|
||||
|
||||
- Inputs will be an array of positive integers only.
|
||||
- Coin can be any positive value.
|
47
Week-04/Day-26_Briefcase-Lock/README.md
Normal file
@ -0,0 +1,47 @@
|
||||
## Briefcase Lock
|
||||
|
||||
A briefcase has a 4-digit **rolling-lock**. Each digit is a number from `0-9` that can be rolled either forwards or backwards.
|
||||
|
||||
Create a function that returns the smallest number of turns it takes to transform the lock from the current combination to the target combination. One turn is equivalent to rolling a number forwards or backwards by one.
|
||||
|
||||
To illustrate:
|
||||
|
||||
- **current-lock**: 4089
|
||||
- **target-lock**: 5672
|
||||
|
||||
What is the minimum number of turns it takes to transform `4089` to `5672`?
|
||||
|
||||
```
|
||||
4 ➞ 5
|
||||
4 ➞ 5 // Forward Turns: 1 <- Min
|
||||
4 ➞ 3 ➞ 2 ➞ 1 ➞ 0 ➞ 9 ➞ 8 ➞ 7 ➞ 6 ➞ 5 // Backward Turns: 9
|
||||
|
||||
0 ➞ 6
|
||||
0 ➞ 1 ➞ 2 ➞ 3 ➞ 4 ➞ 5 ➞ 6 // Forward Turns: 6
|
||||
0 ➞ 9 ➞ 8 ➞ 7 ➞ 6 // Backward Turns: 4 <- Min
|
||||
|
||||
8 ➞ 7
|
||||
8 ➞ 9 ➞ 0 ➞ 1 ➞ 2 ➞ 3 ➞ 4 ➞ 5 ➞ 6 ➞ 7 // Forward Turns: 9
|
||||
8 ➞ 7 // Backward Turns: 1 <- Min
|
||||
|
||||
9 ➞ 2
|
||||
9 ➞ 0 ➞ 1 ➞ 2 // Forward Turns: 3 <- Min
|
||||
9 ➞ 8 ➞ 7 ➞ 6 ➞ 5 ➞ 4 ➞ 3 ➞ 2 // Backward Turns: 7
|
||||
```
|
||||
|
||||
It takes `1 + 4 + 1 + 3 = 9` minimum turns to change the lock from `4089` to `5672`.
|
||||
|
||||
### Example
|
||||
|
||||
```text
|
||||
MinTurns("4089", "5672") ➞ 9
|
||||
|
||||
MinTurns("1111", "1100") ➞ 2
|
||||
|
||||
MinTurns("2391", "4984") ➞ 10
|
||||
```
|
||||
|
||||
### Notes
|
||||
|
||||
- Both locks are in string format.
|
||||
- A `9` rolls forward to `0`, and a `0` rolls backwards to a `9`.
|
53
Week-04/Day-27_Task-Scheduler/README.md
Normal file
@ -0,0 +1,53 @@
|
||||
## Task Scheduler
|
||||
|
||||
Given a characters array `tasks`, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle.
|
||||
|
||||
However, there is a non-negative integer `n` that represents the cooldown period between two **same tasks** (the same letter in the array), that is that there must be at least `n` units of time between any two same tasks.
|
||||
|
||||
Return the least number of units of times that the CPU will take to finish all the given tasks.
|
||||
|
||||
### Examples
|
||||
|
||||
**Example 1**
|
||||
|
||||
```text
|
||||
Input: tasks = ["A","A","A","B","B","B"], n = 2
|
||||
Output: 8
|
||||
|
||||
Explanation:
|
||||
A -> B -> idle -> A -> B -> idle -> A -> B
|
||||
There is at least 2 units of time between any two same tasks.
|
||||
```
|
||||
|
||||
**Example 2**
|
||||
|
||||
```text
|
||||
Input: tasks = ["A","A","A","B","B","B"], n = 0
|
||||
Output: 6
|
||||
|
||||
Explanation: On this case any permutation of size 6 would work since n = 0.
|
||||
["A","A","A","B","B","B"]
|
||||
["A","B","A","B","A","B"]
|
||||
["B","B","B","A","A","A"]
|
||||
...
|
||||
And so on.
|
||||
```
|
||||
|
||||
**Example 3**
|
||||
|
||||
```text
|
||||
Input: tasks = ["A","A","A","A","A","A","B","C","D","E","F","G"], n = 2
|
||||
Output: 16
|
||||
|
||||
Explanation:
|
||||
One possible solution is
|
||||
A -> B -> C -> A -> D -> E -> A -> F -> G -> A -> idle -> idle -> A -> idle -> idle -> A
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Constraints
|
||||
|
||||
- `1 <= task.length <= 104`
|
||||
- `tasks[i]` is upper-case English letter.
|
||||
- The integer `n` is in the range `[0, 100]`.
|
27
Week-04/Day-28_Word-Search/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
## Word Search
|
||||
|
||||
Given a 2D board and a list of words from the dictionary, find all words in the board.
|
||||
|
||||
Each word must be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once in a word.
|
||||
|
||||
### Examples
|
||||
|
||||
```text
|
||||
Input:
|
||||
board = [
|
||||
['o','a','a','n'],
|
||||
['e','t','a','e'],
|
||||
['i','h','k','r'],
|
||||
['i','f','l','v']
|
||||
]
|
||||
words = ["oath","pea","eat","rain"]
|
||||
|
||||
Output: ["eat","oath"]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Note:
|
||||
|
||||
- All inputs are consist of lowercase letters `a-z`.
|
||||
- The values of `words` are distinct.
|
160000
assets/10MB_sample_text.txt
Normal file
80
assets/5kB_sample_text.txt
Normal file
@ -0,0 +1,80 @@
|
||||
0000000000000000000000000000000000000000000000000000000000000
|
||||
1111111111111111111111111111111111111111111111111111111111111
|
||||
2222222222222222222222222222222222222222222222222222222222222
|
||||
3333333333333333333333333333333333333333333333333333333333333
|
||||
4444444444444444444444444444444444444444444444444444444444444
|
||||
5555555555555555555555555555555555555555555555555555555555555
|
||||
6666666666666666666666666666666666666666666666666666666666666
|
||||
7777777777777777777777777777777777777777777777777777777777777
|
||||
8888888888888888888888888888888888888888888888888888888888888
|
||||
9999999999999999999999999999999999999999999999999999999999999
|
||||
0000000000000000000000000000000000000000000000000000000000000
|
||||
1111111111111111111111111111111111111111111111111111111111111
|
||||
2222222222222222222222222222222222222222222222222222222222222
|
||||
3333333333333333333333333333333333333333333333333333333333333
|
||||
4444444444444444444444444444444444444444444444444444444444444
|
||||
5555555555555555555555555555555555555555555555555555555555555
|
||||
6666666666666666666666666666666666666666666666666666666666666
|
||||
7777777777777777777777777777777777777777777777777777777777777
|
||||
8888888888888888888888888888888888888888888888888888888888888
|
||||
9999999999999999999999999999999999999999999999999999999999999
|
||||
0000000000000000000000000000000000000000000000000000000000000
|
||||
1111111111111111111111111111111111111111111111111111111111111
|
||||
2222222222222222222222222222222222222222222222222222222222222
|
||||
3333333333333333333333333333333333333333333333333333333333333
|
||||
4444444444444444444444444444444444444444444444444444444444444
|
||||
5555555555555555555555555555555555555555555555555555555555555
|
||||
6666666666666666666666666666666666666666666666666666666666666
|
||||
7777777777777777777777777777777777777777777777777777777777777
|
||||
8888888888888888888888888888888888888888888888888888888888888
|
||||
9999999999999999999999999999999999999999999999999999999999999
|
||||
0000000000000000000000000000000000000000000000000000000000000
|
||||
1111111111111111111111111111111111111111111111111111111111111
|
||||
2222222222222222222222222222222222222222222222222222222222222
|
||||
3333333333333333333333333333333333333333333333333333333333333
|
||||
4444444444444444444444444444444444444444444444444444444444444
|
||||
5555555555555555555555555555555555555555555555555555555555555
|
||||
6666666666666666666666666666666666666666666666666666666666666
|
||||
7777777777777777777777777777777777777777777777777777777777777
|
||||
8888888888888888888888888888888888888888888888888888888888888
|
||||
9999999999999999999999999999999999999999999999999999999999999
|
||||
0000000000000000000000000000000000000000000000000000000000000
|
||||
1111111111111111111111111111111111111111111111111111111111111
|
||||
2222222222222222222222222222222222222222222222222222222222222
|
||||
3333333333333333333333333333333333333333333333333333333333333
|
||||
4444444444444444444444444444444444444444444444444444444444444
|
||||
5555555555555555555555555555555555555555555555555555555555555
|
||||
6666666666666666666666666666666666666666666666666666666666666
|
||||
7777777777777777777777777777777777777777777777777777777777777
|
||||
8888888888888888888888888888888888888888888888888888888888888
|
||||
9999999999999999999999999999999999999999999999999999999999999
|
||||
0000000000000000000000000000000000000000000000000000000000000
|
||||
1111111111111111111111111111111111111111111111111111111111111
|
||||
2222222222222222222222222222222222222222222222222222222222222
|
||||
3333333333333333333333333333333333333333333333333333333333333
|
||||
4444444444444444444444444444444444444444444444444444444444444
|
||||
5555555555555555555555555555555555555555555555555555555555555
|
||||
6666666666666666666666666666666666666666666666666666666666666
|
||||
7777777777777777777777777777777777777777777777777777777777777
|
||||
8888888888888888888888888888888888888888888888888888888888888
|
||||
9999999999999999999999999999999999999999999999999999999999999
|
||||
0000000000000000000000000000000000000000000000000000000000000
|
||||
1111111111111111111111111111111111111111111111111111111111111
|
||||
2222222222222222222222222222222222222222222222222222222222222
|
||||
3333333333333333333333333333333333333333333333333333333333333
|
||||
4444444444444444444444444444444444444444444444444444444444444
|
||||
5555555555555555555555555555555555555555555555555555555555555
|
||||
6666666666666666666666666666666666666666666666666666666666666
|
||||
7777777777777777777777777777777777777777777777777777777777777
|
||||
8888888888888888888888888888888888888888888888888888888888888
|
||||
9999999999999999999999999999999999999999999999999999999999999
|
||||
0000000000000000000000000000000000000000000000000000000000000
|
||||
1111111111111111111111111111111111111111111111111111111111111
|
||||
2222222222222222222222222222222222222222222222222222222222222
|
||||
3333333333333333333333333333333333333333333333333333333333333
|
||||
4444444444444444444444444444444444444444444444444444444444444
|
||||
5555555555555555555555555555555555555555555555555555555555555
|
||||
6666666666666666666666666666666666666666666666666666666666666
|
||||
7777777777777777777777777777777777777777777777777777777777777
|
||||
8888888888888888888888888888888888888888888888888888888888888
|
||||
9999999999999999999999999999999999999999999999999999999999999
|
BIN
assets/An-Insane-Amount-of-Tweets.png
Normal file
After Width: | Height: | Size: 134 KiB |
BIN
assets/Confusing-Screen-Name.png
Normal file
After Width: | Height: | Size: 115 KiB |
BIN
assets/Dustin.png
Normal file
After Width: | Height: | Size: 17 KiB |
6
assets/Google_G_Logo.svg
Normal file
@ -0,0 +1,6 @@
|
||||
<svg viewBox="0 0 533.5 544.3" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M533.5 278.4c0-18.5-1.5-37.1-4.7-55.3H272.1v104.8h147c-6.1 33.8-25.7 63.7-54.4 82.7v68h87.7c51.5-47.4 81.1-117.4 81.1-200.2z" fill="#4285f4"/>
|
||||
<path d="M272.1 544.3c73.4 0 135.3-24.1 180.4-65.7l-87.7-68c-24.4 16.6-55.9 26-92.6 26-71 0-131.2-47.9-152.8-112.3H28.9v70.1c46.2 91.9 140.3 149.9 243.2 149.9z" fill="#34a853"/>
|
||||
<path d="M119.3 324.3c-11.4-33.8-11.4-70.4 0-104.2V150H28.9c-38.6 76.9-38.6 167.5 0 244.4l90.4-70.1z" fill="#fbbc04"/>
|
||||
<path d="M272.1 107.7c38.8-.6 76.3 14 104.4 40.8l77.7-77.7C405 24.6 339.7-.8 272.1 0 169.2 0 75.1 58 28.9 150l90.4 70.1c21.5-64.5 81.8-112.4 152.8-112.4z" fill="#ea4335"/>
|
||||
</svg>
|
After Width: | Height: | Size: 694 B |
BIN
assets/Has-Not-Tweeted-In-Years.png
Normal file
After Width: | Height: | Size: 115 KiB |
BIN
assets/Incoherent-Tweets.png
Normal file
After Width: | Height: | Size: 84 KiB |
BIN
assets/L33tspeak.gif
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
assets/MARBLES.BMP
Normal file
After Width: | Height: | Size: 4.1 MiB |
BIN
assets/Telephone-keypad2.png
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
assets/The Time in Words.png
Normal file
After Width: | Height: | Size: 36 KiB |
BIN
assets/Twitter-Stock-Image-Profile.png
Normal file
After Width: | Height: | Size: 110 KiB |
BIN
assets/amazon_deforestation.jpg
Normal file
After Width: | Height: | Size: 38 KiB |
51
assets/buzzwords.txt
Normal file
@ -0,0 +1,51 @@
|
||||
Checking A-HA moment
|
||||
Getting Wow moment
|
||||
Supporting customer onboarding
|
||||
Designing customer ongoing follow-up
|
||||
Enabling startup mindset
|
||||
Overinvesting
|
||||
Ensuring Customer Success (CS)
|
||||
Growth hacking
|
||||
Life hacking
|
||||
Getting ROI
|
||||
Building cross-platform methodical Graphical User Interface
|
||||
Requesting Phased next generation task-force
|
||||
Presenting Adaptive zero defect data-warehouse
|
||||
Submitting ergonomic client-server initiative
|
||||
Calling Multi-tiered radical function
|
||||
Detecting Re-engineered transitional knowledge base
|
||||
Gathering Profit-focused logistical focus group
|
||||
Pinging server
|
||||
Wating response
|
||||
Downloading bizz data
|
||||
Compiling data
|
||||
Running checksum
|
||||
Checking diffs
|
||||
Pooling object cache
|
||||
Enabling secure mode
|
||||
Dispatching threads
|
||||
Acquiring locks
|
||||
Cloning repo
|
||||
Rollback changes
|
||||
Applying updates
|
||||
Garbage collecting
|
||||
Pushing code
|
||||
Checking thermal levels
|
||||
Updating JIRA
|
||||
Auto generating PPTs for meetings
|
||||
Preparing coffee
|
||||
Re-engineering demand-driven hub
|
||||
Querying BIG DATA
|
||||
Leveraging the CLOUD strategy
|
||||
Creating Disruptive data
|
||||
Checking Corporate Culture
|
||||
Buying-in
|
||||
Discovering innovative breakthrough
|
||||
Calling Stakeholders
|
||||
Turning ON extra Advertainments
|
||||
Breaking BLOCKCHAIN
|
||||
Mining Bitcoin
|
||||
Checking People Analytics
|
||||
Applying Scrum
|
||||
Double clicking
|
||||
Giving back your time
|
6
assets/day-35_sample_1_valid.txt
Normal file
@ -0,0 +1,6 @@
|
||||
1 1.000 1.000 2.000 2.000
|
||||
1.500 1.500
|
||||
|
||||
2 2.000 2.000 1.000 1.000
|
||||
1.500 1.500
|
||||
2.500 2.500
|
18
assets/day-35_sample_2_valid.txt
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
1 1.000 1.000 2.000 2.000
|
||||
1.500 1.500
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
2 2.000 2.000 1.000 1.000
|
||||
1.500 1.500
|
||||
2.500 2.500
|
||||
|
||||
|
||||
|
6
assets/day-35_sample_3_invalid.txt
Normal file
@ -0,0 +1,6 @@
|
||||
1 1.000 1.000 2.000 2.000
|
||||
1.500 1.500
|
||||
|
||||
3 2.000 2.000 1.000 1.000
|
||||
1.500 1.500
|
||||
2.500 2.500
|
6
assets/day-35_sample_4_invalid.txt
Normal file
@ -0,0 +1,6 @@
|
||||
1 1.000 1.000 2.000 2.000
|
||||
1.500 1.500
|
||||
|
||||
2 2.000 2.000 1.000
|
||||
1.500 1.500
|
||||
2.500 2.500
|
6
assets/day-35_sample_5_invalid.txt
Normal file
@ -0,0 +1,6 @@
|
||||
1 1.000 1.000 2.000 2.000
|
||||
1.500 1.500
|
||||
|
||||
2 2.000 2.000 1.000 1.000 1.000
|
||||
1.500 1.500
|
||||
2.500 2.500
|
172820
assets/dictionary1.txt
Normal file
BIN
assets/dining_philosophers_problem.png
Normal file
After Width: | Height: | Size: 596 KiB |
BIN
assets/google_logo.png
Normal file
After Width: | Height: | Size: 81 KiB |
BIN
assets/google_logo_2.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
assets/josephus-problem.jpg
Normal file
After Width: | Height: | Size: 101 KiB |
BIN
assets/keyboard.png
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
assets/lcd.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
assets/maze.png
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
assets/maze_color_1.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
assets/maze_color_2.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
assets/page1.png
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
assets/page1_to_5.png
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
assets/rainwatertrap.png
Normal file
After Width: | Height: | Size: 7.7 KiB |
BIN
assets/robot_maze.png
Normal file
After Width: | Height: | Size: 9.5 KiB |
BIN
assets/twitter-egghead.png
Normal file
After Width: | Height: | Size: 76 KiB |
BIN
assets/url_shortener.png
Normal file
After Width: | Height: | Size: 100 KiB |