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
| DROP TABLE if EXISTS students; | |
| DROP TABLE if EXISTS papers; | |
| CREATE TABLE students( | |
| id SERIAL PRIMARY KEY, | |
| first_name VARCHAR(50) NOT NULL | |
| ); | |
| CREATE TABLE papers( | |
| id SERIAL PRIMARY KEY, | |
| title VARCHAR(255), |
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
| CREATE TABLE driver( | |
| driver_id INTEGER, | |
| country TEXT NOT NULL, | |
| zip_code TEXT NOT NULL, | |
| PRIMARY KEY(driver_id) | |
| ); | |
| CREATE TABLE car( | |
| car_id INTEGER, | |
| brand TEXT NOT NULL, |
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
| CREATE TABLE driver( | |
| driver_id INTEGER, | |
| country TEXT NOT NULL, | |
| zip_code TEXT NOT NULL, | |
| PRIMARY KEY(driver_id) | |
| ); | |
| CREATE TABLE car( | |
| car_id INTEGER, | |
| brand TEXT NOT NULL, |
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 maxNumberOfBalloons(text: string): number { | |
| let result = new Map() | |
| for (let i = 0; i < text.length; i++) { | |
| result.set(text[i],(result.get(text[i]) || 0) + 1) | |
| } | |
| let count = 0 | |
| if (result.get('l') >= result.get('b') * 2) { | |
| count = result.get('b') | |
| } else { | |
| count = Math.floor(result.get('l') / 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
| // Time: O(n) -- Space: O(1) -- Counting Elements | |
| function countElements(arr: number[]): number { | |
| // Create count variable | |
| let count = 0 | |
| // Loop to check next element if equal current element + 1 | |
| for (let i = 0; i < arr.length; i++) { | |
| if(arr[i + 1] === arr[i] + 1) { | |
| count++ | |
| } |
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
| // Time: O(n) -- Space: O(n) -- Two Sum | |
| function twoSum(nums: number[], target: number): number[] { | |
| // Create map | |
| let output = new Map() | |
| // Loop the array | |
| for(let i = 0; i < nums.length; i++) { | |
| // Create substract | |
| let sub = target - nums[i] |
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
| // Time: O(n) -- Space: O(1) -- Pair with target Sum | |
| const pair_with_targetsum = function ( | |
| arr: number[], | |
| target_sum: number, | |
| ): number[] { | |
| // Create two pointers | |
| let i = 0 | |
| let j = arr.length - 1 | |
| // Loop the array |
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
| const remove_duplicates = function (arr: number[]): number { | |
| let i = 1 | |
| let j = 0 | |
| while (j < arr.length) { | |
| if (arr[j] > arr[i]) { | |
| i++ | |
| } | |
| j++ | |
| } | |
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
| // O(n) time complexity || O(1) space complexity | |
| function runningSum(nums: number[]): number[] { | |
| let pointer = 0; | |
| for (let i = 0; i < nums.length; i++) { | |
| nums[i] = nums[i] + pointer; | |
| pointer = nums[i]; | |
| } | |
| return nums; | |
| } |
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
| const mergeAndSort = (array1: number[], array2: number[]): number[] => { | |
| array1.length += array2.length; | |
| for (let i = array1.length - array2.length; i < array1.length; i++) { | |
| array1[i] = array2[i - array1.length + array2.length]; | |
| } | |
| for (let i = 0; i < array1.length; i++) { | |
| for (let j = array1.length; j > i; j--) { | |
| if (array1[j] < array1[i]) { | |
| const temp = array1[i]; |
NewerOlder