Problem: Find two numbers in the array that add up to a specific target.
Solution:
function twoSum(nums: number[], target: number): number[] {
const map = new Map(); // Value to index map| #!/usr/bin/env bash | |
| ### README | |
| ## Make script executable | |
| # chmod +x ./refresh.sh | |
| ## Run the script | |
| # ./refresh.sh | |
| ## Update packages | |
| # ./refresh.sh --upgrade-deps latest --upgrade-all |
| Commands and Links: | |
| Update & Upgrade: | |
| sudo apt update; sudo apt upgrade | |
| Install Favorite Apps: | |
| sudo apt install vlc gimp gparted synaptic | |
| Install Ubuntu Restricted Extras (Media Codecs): | |
| sudo apt install ubuntu-restricted-extras |
| # Set the prefix to Ctrl+a | |
| set -g prefix C-a | |
| # Remove the old prefix | |
| unbind C-b | |
| # Send Ctrl+a to applications by pressing it twice | |
| bind C-a send-prefix | |
| # List of plugins |
| # THIS LINUX SETUP SCRIPT HAS MORPHED INTO A WHOLE PROJECT: HTTPS://OMAKUB.ORG | |
| # PLEASE CHECKOUT THAT PROJECT INSTEAD OF THIS OUTDATED SETUP SCRIPT. | |
| # | |
| # | |
| # Libraries and infrastructure | |
| sudo apt update -y | |
| sudo apt install -y \ | |
| docker.io docker-buildx \ | |
| build-essential pkg-config autoconf bison rustc cargo clang \ |
| { | |
| "users": [ | |
| { | |
| "name": "Karan Ahuja", | |
| "type": 1 | |
| }, | |
| { | |
| "name": "Suraj Singh", | |
| "type": 0 | |
| }, |
| // Example 1 Generic Function | |
| function convertToArrayLegacy<T>(value: T): T[] { // | |
| return [value] | |
| } | |
| const convertToArray = <T extends unknown>(value: T): T[] => { | |
| return [value] | |
| } |
| function binarySearch(nums, target) { | |
| let left = 0; | |
| let right = nums.length - 1 | |
| while (left <= right) { | |
| let mid = ~~((left + right)/2) | |
| if (nums[mid] === target) return mid | |
| if (nums[mid] < target) left = mid + 1 | |
| if (target < nums[mid]) right = mid - 1 | |
| } |
| -- This is Ashish's NVIM Config Dotfile. | |
| -- Set <space> as the leader key | |
| -- See `:help mapleader` | |
| -- NOTE: Must happen before plugins are required (otherwise wrong leader will be used) | |
| vim.g.mapleader = ' ' | |
| vim.g.maplocalleader = ' ' | |
| -- Install package manager |