Skip to content

Instantly share code, notes, and snippets.

View ahmadsb86's full-sized avatar
🌴
On vacation

Ahmad Bilal ahmadsb86

🌴
On vacation
View GitHub Profile
/*
Given the constraints in the problem, our algo has to be at most O(n log n). We can acheive this bound using binary search
Suppose we have already created a function f(x) which, in O(n) time, can compute whether or not a subarray exists with median greater than (or equal to) x. Then, answering this question becomes as simple as finding the largest value of x such that f(x) is true. Finding this largest value of x can be done in O(log n) time with the method explained below.
If the maximum median of a test case is 5, the outputs of f(x) would look something like the following:
x: 1 2 3 4 5 6 7 8 9
f(x): T T T T T F F F F
@ahmadsb86
ahmadsb86 / keybindings.json
Created October 24, 2023 20:05
CPP keybinds
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "ctrl+enter",
"command": "code-runner.run"
},
{
"key": "ctrl+alt+n",
"command": "-code-runner.run"
},
@ahmadsb86
ahmadsb86 / cpp.json
Created October 24, 2023 20:03
CPP Snippets
{
// Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
{
"editor.fontSize": 18,
"terminal.integrated.fontSize": 12,
"editor.fontFamily": "\"Fira Code Light\", \"Monoid\", \"JetBrainsMono Nerd Font Mono\"",
"workbench.colorTheme": "Dare (rainglow)",
"code-runner.executorMap": {
// "cpp": "cls && cd $dir && g++ $fileName -o \"C:\\Users\\ahmad\\OneDrive\\Desktop\\Coding\\IO\\bin\\$fileNameWithoutExt\" && C:\\Users\\ahmad\\OneDrive\\Desktop\\Coding\\IO\\bin\\$fileNameWithoutExt <C:\\Users\\ahmad\\OneDrive\\Desktop\\Coding\\IO\\input.txt> C:\\Users\\ahmad\\OneDrive\\Desktop\\Coding\\IO\\output.txt",
"cpp": "cls && cd $dir && g++ $fileName -o \"C:\\Users\\ahmad\\Desktop\\Coding\\!Workspace\\bin\\$fileNameWithoutExt\" && C:\\Users\\ahmad\\Desktop\\Coding\\!Workspace\\bin\\$fileNameWithoutExt <C:\\Users\\ahmad\\Desktop\\Coding\\!Workspace\\input.txt> C:\\Users\\ahmad\\Desktop\\Coding\\!Workspace\\output.txt"
},
"code-runner.runInTerminal": true,
package main
import (
"fmt"
"math"
)
//Linked list structs
type node struct {
val int
package main
import(
"fmt"
"math"
)
func main(){
//Input (hardcode values if you are using Go Playground since it doesn't support terminal input)
var inputs [2]int