├── scripts ├── node_modules │ ├── node-domexception │ │ ├── .history │ │ │ ├── index_20210527203842.js │ │ │ ├── test_20210527205603.js │ │ │ ├── test_20210527205957.js │ │ │ ├── test_20210527210021.js │ │ │ ├── README_20210527203617.md │ │ │ ├── index_20210527203947.js │ │ │ ├── index_20210527204259.js │ │ │ ├── index_20210527204418.js │ │ │ ├── index_20210527204756.js │ │ │ ├── index_20210527204833.js │ │ │ ├── index_20210527211208.js │ │ │ ├── index_20210527211248.js │ │ │ ├── index_20210527212746.js │ │ │ ├── index_20210527213910.js │ │ │ ├── index_20210527214034.js │ │ │ ├── index_20210527214700.js │ │ │ ├── index_20210527212900.js │ │ │ ├── package_20210527203825.json │ │ │ ├── index_20210527213022.js │ │ │ ├── index_20210527213822.js │ │ │ ├── index_20210527213843.js │ │ │ ├── index_20210527213852.js │ │ │ ├── package_20210527204621.json │ │ │ ├── package_20210527203733.json │ │ │ ├── package_20210527204913.json │ │ │ ├── package_20210527204925.json │ │ │ ├── package_20210527205145.json │ │ │ ├── package_20210527205156.json │ │ │ ├── index_20210527212722.js │ │ │ ├── index_20210527212731.js │ │ │ ├── index_20210527214643.js │ │ │ ├── index_20210527214654.js │ │ │ ├── README_20210527213345.md │ │ │ ├── README_20210527213411.md │ │ │ ├── README_20210527213803.md │ │ │ ├── README_20210527212714.md │ │ │ ├── README_20210527214323.md │ │ │ └── README_20210527214408.md │ │ ├── index.js │ │ ├── package.json │ │ ├── LICENSE │ │ └── README.md │ ├── fetch-blob │ │ ├── file.d.ts │ │ ├── index.d.ts │ │ ├── from.d.ts │ │ ├── LICENSE │ │ ├── file.js │ │ ├── streams.cjs │ │ ├── package.json │ │ └── from.js │ ├── formdata-polyfill │ │ ├── esm.min.d.ts │ │ ├── LICENSE │ │ ├── formdata-to-blob.js │ │ ├── package.json │ │ └── esm.min.js │ ├── node-fetch │ │ ├── src │ │ │ ├── errors │ │ │ │ ├── abort-error.js │ │ │ │ ├── base.js │ │ │ │ └── fetch-error.js │ │ │ ├── utils │ │ │ │ ├── is-redirect.js │ │ │ │ ├── get-search.js │ │ │ │ └── is.js │ │ │ └── response.js │ │ ├── LICENSE.md │ │ └── package.json │ ├── web-streams-polyfill │ │ ├── ponyfill │ │ │ ├── package.json │ │ │ ├── es6 │ │ │ │ └── package.json │ │ │ └── es2018 │ │ │ │ └── package.json │ │ ├── es6 │ │ │ └── package.json │ │ ├── dist │ │ │ └── types │ │ │ │ ├── tsdoc-metadata.json │ │ │ │ ├── ts3.6 │ │ │ │ └── polyfill.d.ts │ │ │ │ └── polyfill.d.ts │ │ ├── es2018 │ │ │ └── package.json │ │ ├── LICENSE │ │ └── package.json │ ├── data-uri-to-buffer │ │ ├── dist │ │ │ ├── index.d.ts │ │ │ ├── index.js.map │ │ │ └── index.js │ │ ├── package.json │ │ ├── src │ │ │ └── index.ts │ │ └── README.md │ └── .package-lock.json ├── package.json ├── package-lock.json └── index.js ├── _config.yml ├── 2220-minimum-bit-flips-to-convert-number ├── minimum-bit-flips-to-convert-number.java └── README.md ├── .gitignore ├── 1894-find-the-student-that-will-replace-the-chalk ├── find-the-student-that-will-replace-the-chalk.java └── README.md ├── 2807-insert-greatest-common-divisors-in-linked-list ├── insert-greatest-common-divisors-in-linked-list.java └── README.md ├── 729-my-calendar-i ├── my-calendar-i.java └── README.md ├── 2132-convert-1d-array-into-2d-array ├── convert-1d-array-into-2d-array.java └── README.md ├── 179-largest-number ├── largest-number.java └── README.md ├── 2419-longest-subarray-with-maximum-bitwise-and ├── longest-subarray-with-maximum-bitwise-and.java └── README.md ├── 3163-string-compression-iii ├── string-compression-iii.java └── README.md ├── 1945-sum-of-digits-of-string-after-convert ├── sum-of-digits-of-string-after-convert.java └── README.md ├── 731-my-calendar-ii ├── my-calendar-ii.java └── README.md ├── 1684-count-the-number-of-consistent-strings ├── count-the-number-of-consistent-strings.java └── README.md ├── 2028-find-missing-observations ├── find-missing-observations.java └── README.md ├── 386-lexicographical-numbers ├── lexicographical-numbers.java └── README.md ├── 1310-xor-queries-of-a-subarray ├── xor-queries-of-a-subarray.java └── README.md ├── 2938-separate-black-and-white-balls ├── separate-black-and-white-balls.java └── README.md ├── 884-uncommon-words-from-two-sentences ├── uncommon-words-from-two-sentences.java └── README.md ├── 3217-delete-nodes-from-linked-list-present-in-array ├── delete-nodes-from-linked-list-present-in-array.java └── README.md ├── 214-shortest-palindrome ├── shortest-palindrome.java └── README.md ├── 1381-design-a-stack-with-increment-operation ├── design-a-stack-with-increment-operation.java └── README.md ├── 539-minimum-time-difference ├── README.md └── minimum-time-difference.java ├── .github └── workflows │ ├── detect-changes.yml │ ├── readme.yml │ └── jekyll-gh-pages.yml ├── 1371-find-the-longest-substring-containing-vowels-in-even-counts ├── find-the-longest-substring-containing-vowels-in-even-counts.java └── README.md ├── 241-different-ways-to-add-parentheses ├── different-ways-to-add-parentheses.java └── README.md ├── 1367-linked-list-in-binary-tree ├── linked-list-in-binary-tree.java └── README.md ├── 725-split-linked-list-in-parts ├── split-linked-list-in-parts.java └── README.md ├── 440-k-th-smallest-in-lexicographical-order ├── README.md └── k-th-smallest-in-lexicographical-order.java ├── 432-all-oone-data-structure ├── all-oone-data-structure.java └── README.md ├── 2707-extra-characters-in-a-string ├── extra-characters-in-a-string.java └── README.md ├── LICENSE ├── 3043-find-the-length-of-the-longest-common-prefix ├── find-the-length-of-the-longest-common-prefix.java └── README.md ├── 874-walking-robot-simulation ├── walking-robot-simulation.java └── README.md ├── _layouts └── default.html ├── 2326-spiral-matrix-iv ├── spiral-matrix-iv.java └── README.md ├── 2416-sum-of-prefix-scores-of-strings ├── sum-of-prefix-scores-of-strings.java └── README.md ├── LeetSync2-Metadata.txt └── 641-design-circular-deque ├── design-circular-deque.java └── README.md /scripts/node_modules/node-domexception/.history/index_20210527203842.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/test_20210527205603.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /scripts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module", 3 | "dependencies": { 4 | "node-fetch": "^3.2.0" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/test_20210527205957.js: -------------------------------------------------------------------------------- 1 | require('./index.js') 2 | 3 | console.log(DOMException.INDEX_SIZE_ERR) 4 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/test_20210527210021.js: -------------------------------------------------------------------------------- 1 | const e = require('./index.js') 2 | 3 | console.log(e.INDEX_SIZE_ERR) 4 | -------------------------------------------------------------------------------- /scripts/node_modules/fetch-blob/file.d.ts: -------------------------------------------------------------------------------- 1 | /** @type {typeof globalThis.File} */ export const File: typeof globalThis.File; 2 | export default File; 3 | -------------------------------------------------------------------------------- /scripts/node_modules/fetch-blob/index.d.ts: -------------------------------------------------------------------------------- 1 | /** @type {typeof globalThis.Blob} */ 2 | export const Blob: typeof globalThis.Blob; 3 | export default Blob; 4 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/README_20210527203617.md: -------------------------------------------------------------------------------- 1 | # node-domexception 2 | An implementation of the DOMException class from NodeJS 3 | -------------------------------------------------------------------------------- /scripts/node_modules/formdata-polyfill/esm.min.d.ts: -------------------------------------------------------------------------------- 1 | export declare const FormData: { 2 | new (): FormData; 3 | prototype: FormData; 4 | }; 5 | export declare function formDataToBlob(formData: FormData): Blob; 6 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | title: September-Leetcode-Daily-2024 2 | description: A Repository to maintain my September Leetcode Coding session 2024 3 | show_downloads: false 4 | google_analytics: 5 | theme: jekyll-theme-hacker 6 | markdown: GFM 7 | include: 8 | - README.md 9 | - LICENSE 10 | -------------------------------------------------------------------------------- /scripts/node_modules/node-fetch/src/errors/abort-error.js: -------------------------------------------------------------------------------- 1 | import {FetchBaseError} from './base.js'; 2 | 3 | /** 4 | * AbortError interface for cancelled requests 5 | */ 6 | export class AbortError extends FetchBaseError { 7 | constructor(message, type = 'aborted') { 8 | super(message, type); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /scripts/node_modules/node-fetch/src/utils/is-redirect.js: -------------------------------------------------------------------------------- 1 | const redirectStatus = new Set([301, 302, 303, 307, 308]); 2 | 3 | /** 4 | * Redirect code matching 5 | * 6 | * @param {number} code - Status code 7 | * @return {boolean} 8 | */ 9 | export const isRedirect = code => { 10 | return redirectStatus.has(code); 11 | }; 12 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527203947.js: -------------------------------------------------------------------------------- 1 | const { MessageChannel } = require('worker_threads') 2 | 3 | if (!globalThis.DOMException) { 4 | const port = new MessageChannel().port1 5 | const ab = new ArrayBuffer() 6 | try { port.postMessage(ab, [ab, ab]) } 7 | catch (err) { globalThis.DOMException = err.constructor } 8 | } 9 | -------------------------------------------------------------------------------- /2220-minimum-bit-flips-to-convert-number/minimum-bit-flips-to-convert-number.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int minBitFlips(int start, int goal) { 3 | int ans = 0; 4 | int xor = start ^ goal; 5 | 6 | while(xor!=0){ 7 | ans += xor & 1; 8 | xor >>=1; 9 | } 10 | return ans; 11 | } 12 | } -------------------------------------------------------------------------------- /scripts/node_modules/web-streams-polyfill/ponyfill/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web-streams-ponyfill", 3 | "main": "../dist/ponyfill", 4 | "module": "../dist/ponyfill.mjs", 5 | "types": "../dist/types/ponyfill.d.ts", 6 | "typesVersions": { 7 | ">=3.6": { 8 | "../dist/types/*": [ 9 | "../dist/types/ts3.6/*" 10 | ] 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527204259.js: -------------------------------------------------------------------------------- 1 | if (!globalThis.DOMException) { 2 | const { MessageChannel } = require('worker_threads') 3 | const port = new MessageChannel().port1 4 | const ab = new ArrayBuffer() 5 | try { port.postMessage(ab, [ab, ab]) } 6 | catch (err) { globalThis.DOMException = err.constructor } 7 | } 8 | 9 | module.exports 10 | -------------------------------------------------------------------------------- /scripts/node_modules/node-fetch/src/utils/get-search.js: -------------------------------------------------------------------------------- 1 | export const getSearch = parsedURL => { 2 | if (parsedURL.search) { 3 | return parsedURL.search; 4 | } 5 | 6 | const lastOffset = parsedURL.href.length - 1; 7 | const hash = parsedURL.hash || (parsedURL.href[lastOffset] === '#' ? '#' : ''); 8 | return parsedURL.href[lastOffset - hash.length] === '?' ? '?' : ''; 9 | }; 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | replay_pid* 25 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527204418.js: -------------------------------------------------------------------------------- 1 | if (!globalThis.DOMException) { 2 | const { MessageChannel } = require('worker_threads') 3 | const port = new MessageChannel().port1 4 | const ab = new ArrayBuffer() 5 | try { port.postMessage(ab, [ab, ab]) } 6 | catch (err) { globalThis.DOMException = err.constructor } 7 | } 8 | 9 | module.exports = globalThis.DOMException 10 | -------------------------------------------------------------------------------- /scripts/node_modules/web-streams-polyfill/ponyfill/es6/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web-streams-ponyfill-es6", 3 | "main": "../../dist/ponyfill.es6", 4 | "module": "../../dist/ponyfill.es6.mjs", 5 | "types": "../../dist/types/ponyfill.d.ts", 6 | "typesVersions": { 7 | ">=3.6": { 8 | "../../dist/types/*": [ 9 | "../../dist/types/ts3.6/*" 10 | ] 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /scripts/node_modules/web-streams-polyfill/ponyfill/es2018/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web-streams-ponyfill-es2018", 3 | "main": "../../dist/ponyfill.es2018", 4 | "module": "../../dist/ponyfill.es2018.mjs", 5 | "types": "../../dist/types/ponyfill.d.ts", 6 | "typesVersions": { 7 | ">=3.6": { 8 | "../../dist/types/*": [ 9 | "../../dist/types/ts3.6/*" 10 | ] 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /scripts/node_modules/web-streams-polyfill/es6/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web-streams-polyfill-es6", 3 | "main": "../dist/polyfill.es6", 4 | "browser": "../dist/polyfill.es6.min.js", 5 | "module": "../dist/polyfill.es6.mjs", 6 | "types": "../dist/types/polyfill.d.ts", 7 | "typesVersions": { 8 | ">=3.6": { 9 | "../dist/types/*": [ 10 | "../dist/types/ts3.6/*" 11 | ] 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /scripts/node_modules/web-streams-polyfill/dist/types/tsdoc-metadata.json: -------------------------------------------------------------------------------- 1 | // This file is read by tools that parse documentation comments conforming to the TSDoc standard. 2 | // It should be published with your NPM package. It should not be tracked by Git. 3 | { 4 | "tsdocVersion": "0.12", 5 | "toolPackages": [ 6 | { 7 | "packageName": "@microsoft/api-extractor", 8 | "packageVersion": "7.39.1" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /scripts/node_modules/web-streams-polyfill/es2018/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web-streams-polyfill-es2018", 3 | "main": "../dist/polyfill.es2018", 4 | "browser": "../dist/polyfill.es2018.min.js", 5 | "module": "../dist/polyfill.es2018.mjs", 6 | "types": "../dist/types/polyfill.d.ts", 7 | "typesVersions": { 8 | ">=3.6": { 9 | "../dist/types/*": [ 10 | "../dist/types/ts3.6/*" 11 | ] 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /1894-find-the-student-that-will-replace-the-chalk/find-the-student-that-will-replace-the-chalk.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int chalkReplacer(int[] chalk, int k) { 3 | long accSum = 0; 4 | for (int c : chalk) accSum += c; 5 | 6 | k %= accSum; 7 | 8 | for (int i = 0; i < chalk.length; i++) { 9 | if (chalk[i] > k) return i; 10 | k -= chalk[i]; 11 | } 12 | return -1; 13 | } 14 | } -------------------------------------------------------------------------------- /scripts/node_modules/node-fetch/src/errors/base.js: -------------------------------------------------------------------------------- 1 | export class FetchBaseError extends Error { 2 | constructor(message, type) { 3 | super(message); 4 | // Hide custom error implementation details from end-users 5 | Error.captureStackTrace(this, this.constructor); 6 | 7 | this.type = type; 8 | } 9 | 10 | get name() { 11 | return this.constructor.name; 12 | } 13 | 14 | get [Symbol.toStringTag]() { 15 | return this.constructor.name; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527204756.js: -------------------------------------------------------------------------------- 1 | /*! blob-to-buffer. MIT License. Jimmy Wärting */ 2 | 3 | if (!globalThis.DOMException) { 4 | const { MessageChannel } = require('worker_threads') 5 | const port = new MessageChannel().port1 6 | const ab = new ArrayBuffer() 7 | try { port.postMessage(ab, [ab, ab]) } 8 | catch (err) { globalThis.DOMException = err.constructor } 9 | } 10 | 11 | module.exports = globalThis.DOMException 12 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527204833.js: -------------------------------------------------------------------------------- 1 | /*! blob-to-buffer. MIT License. Jimmy Wärting */ 2 | 3 | if (!globalThis.DOMException) { 4 | const { MessageChannel } = require('worker_threads') 5 | const port = new MessageChannel().port1 6 | const ab = new ArrayBuffer() 7 | try { port.postMessage(ab, [ab, ab]) } 8 | catch (err) { globalThis.DOMException = err.constructor } 9 | } 10 | 11 | module.exports = globalThis.DOMException 12 | -------------------------------------------------------------------------------- /2807-insert-greatest-common-divisors-in-linked-list/insert-greatest-common-divisors-in-linked-list.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | private int gcd(int a, int b) { 3 | if (b == 0) return a; 4 | return gcd(b, a % b); 5 | } 6 | 7 | public ListNode insertGreatestCommonDivisors(ListNode head) { 8 | var p = head; 9 | 10 | while (p.next != null) { 11 | var newNode = new ListNode(gcd(p.val, p.next.val), p.next); 12 | p.next = newNode; 13 | p = newNode.next; 14 | } 15 | return head; 16 | } 17 | } -------------------------------------------------------------------------------- /729-my-calendar-i/my-calendar-i.java: -------------------------------------------------------------------------------- 1 | class MyCalendar { 2 | TreeMap calcy; 3 | public MyCalendar() { 4 | calcy = new TreeMap(); 5 | 6 | } 7 | 8 | public boolean book(int start, int end) { 9 | Integer prevBook = calcy.floorKey(start); 10 | Integer nextBook = calcy.ceilingKey(start); 11 | if((prevBook==null || calcy.get(prevBook)<=start) && (nextBook==null || end<=nextBook)) 12 | { 13 | calcy.put(start, end); 14 | return true; 15 | } 16 | return false; 17 | } 18 | } -------------------------------------------------------------------------------- /scripts/node_modules/data-uri-to-buffer/dist/index.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | export interface MimeBuffer extends Buffer { 3 | type: string; 4 | typeFull: string; 5 | charset: string; 6 | } 7 | /** 8 | * Returns a `Buffer` instance from the given data URI `uri`. 9 | * 10 | * @param {String} uri Data URI to turn into a Buffer instance 11 | * @returns {Buffer} Buffer instance from Data URI 12 | * @api public 13 | */ 14 | export declare function dataUriToBuffer(uri: string): MimeBuffer; 15 | export default dataUriToBuffer; 16 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/index.js: -------------------------------------------------------------------------------- 1 | /*! node-domexception. MIT License. Jimmy Wärting */ 2 | 3 | if (!globalThis.DOMException) { 4 | try { 5 | const { MessageChannel } = require('worker_threads'), 6 | port = new MessageChannel().port1, 7 | ab = new ArrayBuffer() 8 | port.postMessage(ab, [ab, ab]) 9 | } catch (err) { 10 | err.constructor.name === 'DOMException' && ( 11 | globalThis.DOMException = err.constructor 12 | ) 13 | } 14 | } 15 | 16 | module.exports = globalThis.DOMException 17 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527211208.js: -------------------------------------------------------------------------------- 1 | /*! blob-to-buffer. MIT License. Jimmy Wärting */ 2 | 3 | if (!globalThis.DOMException) { 4 | var { MessageChannel } = require('worker_threads'), 5 | port = new MessageChannel().port1, 6 | ab = new ArrayBuffer() 7 | try { port.postMessage(ab, [ab, ab]) } 8 | catch (err) { 9 | err.constructor.name === 'DOMException' && ( 10 | globalThis.DOMException = err.constructor 11 | ) 12 | } 13 | } 14 | 15 | module.exports = globalThis.DOMException 16 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527211248.js: -------------------------------------------------------------------------------- 1 | /*! blob-to-buffer. MIT License. Jimmy Wärting */ 2 | 3 | if (!globalThis.DOMException) { 4 | const { MessageChannel } = require('worker_threads'), 5 | port = new MessageChannel().port1, 6 | ab = new ArrayBuffer() 7 | try { port.postMessage(ab, [ab, ab]) } 8 | catch (err) { 9 | err.constructor.name === 'DOMException' && ( 10 | globalThis.DOMException = err.constructor 11 | ) 12 | } 13 | } 14 | 15 | module.exports = globalThis.DOMException 16 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527212746.js: -------------------------------------------------------------------------------- 1 | /*! blob-to-buffer. MIT License. Jimmy Wärting */ 2 | 3 | if (!globalThis.DOMException) { 4 | const { MessageChannel } = require('worker_threads'), 5 | port = new MessageChannel().port1, 6 | ab = new ArrayBuffer() 7 | try { port.postMessage(ab, [ab, ab]) } 8 | catch (err) { 9 | err.constructor.name === 'DOMException' && ( 10 | globalThis.DOMException = err.constructor 11 | ) 12 | } 13 | } 14 | 15 | module.exports = globalThis.DOMException 16 | -------------------------------------------------------------------------------- /2132-convert-1d-array-into-2d-array/convert-1d-array-into-2d-array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[][] construct2DArray(int[] original, int m, int n) { 3 | int len=original.length; 4 | if(len!=m*n) 5 | { 6 | return new int[0][0]; 7 | } 8 | 9 | int[][] twoD=new int[m][n]; 10 | int k=0; 11 | 12 | for(int i=0;i */ 2 | 3 | if (!globalThis.DOMException) { 4 | try { 5 | const { MessageChannel } = require('worker_threads'), 6 | port = new MessageChannel().port1, 7 | ab = new ArrayBuffer() 8 | port.postMessage(ab, [ab, ab]) 9 | } catch (err) { 10 | err.constructor.name === 'DOMException' && ( 11 | globalThis.DOMException = err.constructor 12 | ) 13 | } 14 | } 15 | 16 | module.exports = globalThis.DOMException 17 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527214034.js: -------------------------------------------------------------------------------- 1 | /*! node-domexception. MIT License. Jimmy Wärting */ 2 | 3 | if (!globalThis.DOMException) { 4 | try { 5 | const { MessageChannel } = require('worker_threads'), 6 | port = new MessageChannel().port1, 7 | ab = new ArrayBuffer() 8 | port.postMessage(ab, [ab, ab]) 9 | } catch (err) { 10 | err.constructor.name === 'DOMException' && ( 11 | globalThis.DOMException = err.constructor 12 | ) 13 | } 14 | } 15 | 16 | module.exports = globalThis.DOMException 17 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527214700.js: -------------------------------------------------------------------------------- 1 | /*! node-domexception. MIT License. Jimmy Wärting */ 2 | 3 | if (!globalThis.DOMException) { 4 | try { 5 | const { MessageChannel } = require('worker_threads'), 6 | port = new MessageChannel().port1, 7 | ab = new ArrayBuffer() 8 | port.postMessage(ab, [ab, ab]) 9 | } catch (err) { 10 | err.constructor.name === 'DOMException' && ( 11 | globalThis.DOMException = err.constructor 12 | ) 13 | } 14 | } 15 | 16 | module.exports = globalThis.DOMException 17 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527212900.js: -------------------------------------------------------------------------------- 1 | /*! blob-to-buffer. MIT License. Jimmy Wärting */ 2 | 3 | if (!globalThis.DOMException) { 4 | const { MessageChannel } = require('worker_threads'), 5 | port = new MessageChannel().port1, 6 | ab = new ArrayBuffer() 7 | try { port.postMessage(ab, [ab, ab]) } 8 | catch (err) { 9 | console.log(err.code) 10 | err.constructor.name === 'DOMException' && ( 11 | globalThis.DOMException = err.constructor 12 | ) 13 | } 14 | } 15 | 16 | module.exports = globalThis.DOMException 17 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/package_20210527203825.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-domexception", 3 | "version": "1.0.0", 4 | "description": "An implementation of the DOMException class from NodeJS", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/jimmywarting/node-domexception.git" 9 | }, 10 | "author": "Jimmy Wärting", 11 | "license": "MIT", 12 | "bugs": { 13 | "url": "https://github.com/jimmywarting/node-domexception/issues" 14 | }, 15 | "homepage": "https://github.com/jimmywarting/node-domexception#readme" 16 | } 17 | -------------------------------------------------------------------------------- /179-largest-number/largest-number.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String largestNumber(int[] nums) { 3 | String[] array = new String[nums.length]; 4 | for(int i=0; i (b+a).compareTo(a+b)); 8 | if(array[0].equals("0")){ 9 | return "0"; 10 | } 11 | StringBuilder largest = new StringBuilder(); 12 | for(int i=0; i */ 2 | 3 | if (!globalThis.DOMException) { 4 | const { MessageChannel } = require('worker_threads'), 5 | port = new MessageChannel().port1, 6 | ab = new ArrayBuffer() 7 | try { port.postMessage(ab, [ab, ab]) } 8 | catch (err) { 9 | console.log(err.code, err.name, err.message) 10 | err.constructor.name === 'DOMException' && ( 11 | globalThis.DOMException = err.constructor 12 | ) 13 | } 14 | } 15 | 16 | module.exports = globalThis.DOMException 17 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527213822.js: -------------------------------------------------------------------------------- 1 | /*! node-DOMException. MIT License. Jimmy Wärting */ 2 | 3 | if (!globalThis.DOMException) { 4 | const { MessageChannel } = require('worker_threads'), 5 | port = new MessageChannel().port1, 6 | ab = new ArrayBuffer() 7 | try { port.postMessage(ab, [ab, ab]) } 8 | catch (err) { 9 | console.log(err.code, err.name, err.message) 10 | err.constructor.name === 'DOMException' && ( 11 | globalThis.DOMException = err.constructor 12 | ) 13 | } 14 | } 15 | 16 | module.exports = globalThis.DOMException 17 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527213843.js: -------------------------------------------------------------------------------- 1 | /*! node-DOMException. MIT License. Jimmy Wärting */ 2 | 3 | if (!globalThis.DOMException) { 4 | try { 5 | const { MessageChannel } = require('worker_threads'), 6 | port = new MessageChannel().port1, 7 | ab = new ArrayBuffer() 8 | port.postMessage(ab, [ab, ab]) 9 | catch (err) { 10 | console.log(err.code, err.name, err.message) 11 | err.constructor.name === 'DOMException' && ( 12 | globalThis.DOMException = err.constructor 13 | ) 14 | } 15 | } 16 | 17 | module.exports = globalThis.DOMException 18 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527213852.js: -------------------------------------------------------------------------------- 1 | /*! node-DOMException. MIT License. Jimmy Wärting */ 2 | 3 | if (!globalThis.DOMException) { 4 | try { 5 | const { MessageChannel } = require('worker_threads'), 6 | port = new MessageChannel().port1, 7 | ab = new ArrayBuffer() 8 | port.postMessage(ab, [ab, ab]) 9 | } catch (err) { 10 | console.log(err.code, err.name, err.message) 11 | err.constructor.name === 'DOMException' && ( 12 | globalThis.DOMException = err.constructor 13 | ) 14 | } 15 | } 16 | 17 | module.exports = globalThis.DOMException 18 | -------------------------------------------------------------------------------- /2419-longest-subarray-with-maximum-bitwise-and/longest-subarray-with-maximum-bitwise-and.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int longestSubarray(int[] nums) { 3 | int maxVal = 0, ans = 0, currentStreak = 0; 4 | 5 | for (int num : nums) { 6 | if(maxVal < num) { 7 | maxVal = num; 8 | ans = currentStreak = 0; 9 | } 10 | if(maxVal == num){ 11 | currentStreak++; 12 | } else { 13 | currentStreak = 0; 14 | } 15 | ans = Math.max(ans, currentStreak); 16 | } 17 | return ans; 18 | } 19 | } -------------------------------------------------------------------------------- /3163-string-compression-iii/string-compression-iii.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String compressedString(String word) { 3 | StringBuilder comp = new StringBuilder(); 4 | int cnt = 1, n = word.length(); 5 | char ch = word.charAt(0); 6 | for (int i = 1; i < n; i++) { 7 | if (word.charAt(i) == ch && cnt < 9) { 8 | cnt++; 9 | } else { 10 | comp.append(cnt).append(ch); 11 | ch = word.charAt(i); 12 | cnt = 1; 13 | } 14 | } 15 | comp.append(cnt).append(ch); 16 | return comp.toString(); 17 | } 18 | } -------------------------------------------------------------------------------- /1945-sum-of-digits-of-string-after-convert/sum-of-digits-of-string-after-convert.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int getLucky(String s, int k) { 3 | StringBuilder number = new StringBuilder(); 4 | for (char x : s.toCharArray()) { 5 | number.append(x - 'a' + 1); 6 | } 7 | 8 | while (k > 0) { 9 | int temp = 0; 10 | for (char x : number.toString().toCharArray()) { 11 | temp += x - '0'; 12 | } 13 | number = new StringBuilder(String.valueOf(temp)); 14 | k--; 15 | } 16 | return Integer.parseInt(number.toString()); 17 | } 18 | } -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/package_20210527204621.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-domexception", 3 | "version": "1.0.0", 4 | "description": "An implementation of the DOMException class from NodeJS", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/jimmywarting/node-domexception.git" 9 | }, 10 | "engines": { 11 | "node": ">=10.5.0" 12 | }, 13 | "author": "Jimmy Wärting", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/jimmywarting/node-domexception/issues" 17 | }, 18 | "homepage": "https://github.com/jimmywarting/node-domexception#readme" 19 | } 20 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/package_20210527203733.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "domexception", 3 | "version": "1.0.0", 4 | "description": "An implementation of the DOMException class from NodeJS", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/jimmywarting/node-domexception.git" 12 | }, 13 | "author": "", 14 | "license": "ISC", 15 | "bugs": { 16 | "url": "https://github.com/jimmywarting/node-domexception/issues" 17 | }, 18 | "homepage": "https://github.com/jimmywarting/node-domexception#readme" 19 | } 20 | -------------------------------------------------------------------------------- /731-my-calendar-ii/my-calendar-ii.java: -------------------------------------------------------------------------------- 1 | class MyCalendarTwo { 2 | private List bookings, overlaps; 3 | public MyCalendarTwo() { 4 | bookings = new ArrayList<>(); 5 | overlaps = new ArrayList<>(); 6 | } 7 | public boolean book(int start, int end) { 8 | for (int[] i : overlaps) { 9 | if (start < i[1] && end > i[0]) return false; 10 | } 11 | for (int[] j : bookings) { 12 | if (start < j[1] && end > j[0]) { 13 | overlaps.add(new int[]{Math.max(start, j[0]), Math.min(end, j[1])}); 14 | } 15 | } 16 | bookings.add(new int[]{start, end}); 17 | return true; 18 | } 19 | } -------------------------------------------------------------------------------- /1684-count-the-number-of-consistent-strings/count-the-number-of-consistent-strings.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int countConsistentStrings(String allowed, String[] words) { 3 | Set set=new HashSet<>(); 4 | for(int i=0;i 6 * n || rem < n) return new int[0]; 12 | 13 | int dist = rem / n; 14 | int mod = rem % n; 15 | int [] res = new int[n]; 16 | 17 | for (int i = 0 ; i < n ; i++) res[i] = dist; 18 | 19 | for (int i = 0 ; i < mod ; i++) res[i]++; 20 | 21 | return res; 22 | } 23 | } -------------------------------------------------------------------------------- /386-lexicographical-numbers/lexicographical-numbers.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List lexicalOrder(int n) { 3 | List result = new ArrayList<>(); 4 | int current = 1; 5 | 6 | for (int i = 0; i < n; i++) { 7 | result.add(current); 8 | 9 | if (current * 10 <= n) { 10 | current *= 10; // Move to the next level by multiplying by 10 11 | } else { 12 | while (current % 10 == 9 || current + 1 > n) { 13 | current /= 10; // Backtrack if we are at the end of a level 14 | } 15 | current++; // Move to the next number 16 | } 17 | } 18 | 19 | return result; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /1310-xor-queries-of-a-subarray/xor-queries-of-a-subarray.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] xorQueries(int[] arr, int[][] queries) { 3 | 4 | int[] ans = new int[queries.length]; 5 | int[] prefix = new int[arr.length]; 6 | prefix[0] = arr[0]; 7 | 8 | // fill the prefix xor array 9 | for(int i=1; i=10.5.0" 12 | }, 13 | "author": "Jimmy Wärting", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/jimmywarting/node-domexception/issues" 17 | }, 18 | "homepage": "https://github.com/jimmywarting/node-domexception#readme", 19 | "funding": [ 20 | { 21 | "type": "github", 22 | "url": "https://github.com/sponsors/jimmywarting" 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/package_20210527204925.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-domexception", 3 | "version": "1.0.0", 4 | "description": "An implementation of the DOMException class from NodeJS", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/jimmywarting/node-domexception.git" 9 | }, 10 | "engines": { 11 | "node": ">=10.5.0" 12 | }, 13 | "author": "Jimmy Wärting", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/jimmywarting/node-domexception/issues" 17 | }, 18 | "homepage": "https://github.com/jimmywarting/node-domexception#readme", 19 | "funding": [ 20 | { 21 | "type": "github", 22 | "url": "https://github.com/sponsors/jimmywarting" 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /2938-separate-black-and-white-balls/separate-black-and-white-balls.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | 3 | public long minimumSteps(String s) { 4 | int whitePosition = 0; 5 | long totalSwaps = 0; 6 | 7 | // Iterate through each ball (character) in the string 8 | for (int currentPos = 0; currentPos < s.length(); currentPos++) { 9 | if (s.charAt(currentPos) == '0') { 10 | // Calculate the number of swaps needed 11 | // to move it to leftmost available position 12 | totalSwaps += currentPos - whitePosition; 13 | 14 | // Move the next available position for a white ball one step to the right 15 | whitePosition++; 16 | } 17 | } 18 | 19 | return totalSwaps; 20 | } 21 | } -------------------------------------------------------------------------------- /884-uncommon-words-from-two-sentences/uncommon-words-from-two-sentences.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String[] uncommonFromSentences(String s1, String s2) { 3 | String[] words1 = s1.split(" "); 4 | Map map = new HashMap<>(); 5 | for(String word: words1){ 6 | map.put(word,map.getOrDefault(word,0)+1); 7 | } 8 | String[] words2 = s2.split(" "); 9 | for(String word: words2){ 10 | map.put(word,map.getOrDefault(word,0)+1); 11 | } 12 | ArrayList ans = new ArrayList<>(); 13 | for(Map.Entry mp: map.entrySet()){ 14 | if(mp.getValue()==1){ 15 | ans.add(mp.getKey()); 16 | } 17 | } 18 | return ans.toArray(new String[0]); 19 | } 20 | } -------------------------------------------------------------------------------- /3217-delete-nodes-from-linked-list-present-in-array/delete-nodes-from-linked-list-present-in-array.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public ListNode modifiedList(int[] nums, ListNode head) { 3 | int max = 0; 4 | for(int ele : nums) { 5 | if(ele > max) max = ele; 6 | } 7 | int count[] = new int[max + 1]; 8 | for(int ele : nums) count[ele] = 1; 9 | 10 | ListNode prev = new ListNode(0); 11 | prev.next = head; 12 | ListNode result = prev; 13 | while(head != null) { 14 | if(head.val <= max && count[head.val] == 1) { 15 | prev.next = head.next; 16 | head = head.next; 17 | } 18 | else { 19 | prev = head; 20 | head = head.next; 21 | } 22 | } 23 | return result.next; 24 | } 25 | } -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-domexception", 3 | "version": "1.0.0", 4 | "description": "An implementation of the DOMException class from NodeJS", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/jimmywarting/node-domexception.git" 9 | }, 10 | "engines": { 11 | "node": ">=10.5.0" 12 | }, 13 | "author": "Jimmy Wärting", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/jimmywarting/node-domexception/issues" 17 | }, 18 | "homepage": "https://github.com/jimmywarting/node-domexception#readme", 19 | "funding": [ 20 | { 21 | "type": "github", 22 | "url": "https://github.com/sponsors/jimmywarting" 23 | }, 24 | { 25 | "type": "github", 26 | "url": "https://paypal.me/jimmywarting" 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/package_20210527205145.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-domexception", 3 | "version": "1.0.0", 4 | "description": "An implementation of the DOMException class from NodeJS", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/jimmywarting/node-domexception.git" 9 | }, 10 | "engines": { 11 | "node": ">=10.5.0" 12 | }, 13 | "author": "Jimmy Wärting", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/jimmywarting/node-domexception/issues" 17 | }, 18 | "homepage": "https://github.com/jimmywarting/node-domexception#readme", 19 | "funding": [ 20 | { 21 | "type": "github", 22 | "url": "https://github.com/sponsors/jimmywarting" 23 | }, 24 | { 25 | "type": "github", 26 | "url": "https://paypal.me/jimmywarting" 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/package_20210527205156.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-domexception", 3 | "version": "1.0.0", 4 | "description": "An implementation of the DOMException class from NodeJS", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/jimmywarting/node-domexception.git" 9 | }, 10 | "engines": { 11 | "node": ">=10.5.0" 12 | }, 13 | "author": "Jimmy Wärting", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/jimmywarting/node-domexception/issues" 17 | }, 18 | "homepage": "https://github.com/jimmywarting/node-domexception#readme", 19 | "funding": [ 20 | { 21 | "type": "github", 22 | "url": "https://github.com/sponsors/jimmywarting" 23 | }, 24 | { 25 | "type": "github", 26 | "url": "https://paypal.me/jimmywarting" 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527212722.js: -------------------------------------------------------------------------------- 1 | /*! blob-to-buffer. MIT License. Jimmy Wärting */ 2 | 3 | if (!globalThis.DOMException) { 4 | const { MessageChannel } = require('worker_threads'), 5 | port = new MessageChannel().port1, 6 | ab = new ArrayBuffer() 7 | try { port.postMessage(ab, [ab, ab]) } 8 | catch (err) { 9 | err.constructor.name === 'DOMException' && ( 10 | globalThis.DOMException = err.constructor 11 | ) 12 | } 13 | } 14 | 15 | module.exports = globalThis.DOMException 16 | 17 | const e1 = new DOMException("Something went wrong", "BadThingsError"); 18 | console.assert(e1.name === "BadThingsError"); 19 | console.assert(e1.code === 0); 20 | 21 | const e2 = new DOMException("Another exciting error message", "NoModificationAllowedError"); 22 | console.assert(e2.name === "NoModificationAllowedError"); 23 | console.assert(e2.code === 7); 24 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527212731.js: -------------------------------------------------------------------------------- 1 | /*! blob-to-buffer. MIT License. Jimmy Wärting */ 2 | 3 | if (!globalThis.DOMException) { 4 | const { MessageChannel } = require('worker_threads'), 5 | port = new MessageChannel().port1, 6 | ab = new ArrayBuffer() 7 | try { port.postMessage(ab, [ab, ab]) } 8 | catch (err) { 9 | err.constructor.name === 'DOMException' && ( 10 | globalThis.DOMException = err.constructor 11 | ) 12 | } 13 | } 14 | 15 | module.exports = globalThis.DOMException 16 | 17 | const e1 = new DOMException("Something went wrong", "BadThingsError"); 18 | console.assert(e1.name === "BadThingsError"); 19 | console.assert(e1.code === 0); 20 | 21 | const e2 = new DOMException("Another exciting error message", "NoModificationAllowedError"); 22 | console.assert(e2.name === "NoModificationAllowedError"); 23 | console.assert(e2.code === 2); 24 | -------------------------------------------------------------------------------- /386-lexicographical-numbers/README.md: -------------------------------------------------------------------------------- 1 |

Lexicographical Numbers

Difficulty: Medium

Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order.

2 | 3 |

You must write an algorithm that runs in O(n) time and uses O(1) extra space. 

4 | 5 |

 

6 |

Example 1:

7 |
Input: n = 13
 8 | Output: [1,10,11,12,13,2,3,4,5,6,7,8,9]
 9 | 

Example 2:

10 |
Input: n = 2
11 | Output: [1,2]
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • 1 <= n <= 5 * 104
  • 18 |
19 | -------------------------------------------------------------------------------- /scripts/node_modules/fetch-blob/from.d.ts: -------------------------------------------------------------------------------- 1 | export default blobFromSync; 2 | /** 3 | * @param {string} path filepath on the disk 4 | * @param {string} [type] mimetype to use 5 | */ 6 | export function blobFromSync(path: string, type?: string): Blob; 7 | import File from "./file.js"; 8 | import Blob from "./index.js"; 9 | /** 10 | * @param {string} path filepath on the disk 11 | * @param {string} [type] mimetype to use 12 | * @returns {Promise} 13 | */ 14 | export function blobFrom(path: string, type?: string): Promise; 15 | /** 16 | * @param {string} path filepath on the disk 17 | * @param {string} [type] mimetype to use 18 | * @returns {Promise} 19 | */ 20 | export function fileFrom(path: string, type?: string): Promise; 21 | /** 22 | * @param {string} path filepath on the disk 23 | * @param {string} [type] mimetype to use 24 | */ 25 | export function fileFromSync(path: string, type?: string): File; 26 | export { File, Blob }; 27 | -------------------------------------------------------------------------------- /214-shortest-palindrome/shortest-palindrome.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public String shortestPalindrome(String s) { 3 | int count = kmp(new StringBuilder(s).reverse().toString(), s); 4 | return new StringBuilder(s.substring(count)).reverse().toString() + s; 5 | } 6 | 7 | private int kmp(String txt, String patt) { 8 | String newString = patt + '#' + txt; 9 | int[] pi = new int[newString.length()]; 10 | int i = 1, k = 0; 11 | while (i < newString.length()) { 12 | if (newString.charAt(i) == newString.charAt(k)) { 13 | k++; 14 | pi[i] = k; 15 | i++; 16 | } else { 17 | if (k > 0) { 18 | k = pi[k - 1]; 19 | } else { 20 | pi[i] = 0; 21 | i++; 22 | } 23 | } 24 | } 25 | return pi[newString.length() - 1]; 26 | } 27 | } -------------------------------------------------------------------------------- /1381-design-a-stack-with-increment-operation/design-a-stack-with-increment-operation.java: -------------------------------------------------------------------------------- 1 | class CustomStack { 2 | private int n; 3 | private Stack stack; 4 | private List inc; 5 | 6 | public CustomStack(int n) { 7 | this.n = n; 8 | this.stack = new Stack<>(); 9 | this.inc = new ArrayList<>(); 10 | } 11 | 12 | public void push(int x) { 13 | if (stack.size() < n) { 14 | stack.push(x); 15 | inc.add(0); 16 | } 17 | } 18 | 19 | public int pop() { 20 | if (stack.isEmpty()) return -1; 21 | if (inc.size() > 1) inc.set(inc.size() - 2, inc.get(inc.size() - 2) + inc.get(inc.size() - 1)); 22 | return stack.pop() + inc.remove(inc.size() - 1); 23 | } 24 | 25 | public void increment(int k, int val) { 26 | if (!stack.isEmpty()) { 27 | int index = Math.min(k, inc.size()) - 1; 28 | inc.set(index, inc.get(index) + val); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /539-minimum-time-difference/README.md: -------------------------------------------------------------------------------- 1 |

Minimum Time Difference

Difficulty: Medium
Given a list of 24-hour clock time points in "HH:MM" format, return the minimum minutes difference between any two time-points in the list. 2 |

 

3 |

Example 1:

4 |
Input: timePoints = ["23:59","00:00"]
 5 | Output: 1
 6 | 

Example 2:

7 |
Input: timePoints = ["00:00","23:59","00:00"]
 8 | Output: 0
 9 | 
10 |

 

11 |

Constraints:

12 | 13 |
    14 |
  • 2 <= timePoints.length <= 2 * 104
  • 15 |
  • timePoints[i] is in the format "HH:MM".
  • 16 |
17 | -------------------------------------------------------------------------------- /.github/workflows/detect-changes.yml: -------------------------------------------------------------------------------- 1 | # .github/workflows/detect-changes.yml 2 | name: Detect Changes and Trigger Workflow 3 | 4 | on: 5 | workflow_dispatch: 6 | push: 7 | branches: 8 | - main # Change this to the branch you want to monitor 9 | pull_request: 10 | branches: 11 | - main # Trigger on pull request to the branch 12 | 13 | jobs: 14 | trigger-workflow: 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - name: Checkout the repository 19 | uses: actions/checkout@v3 20 | 21 | - name: Trigger workflow in another repository 22 | env: 23 | GITHUB_TOKEN: ${{ secrets.SEPTEMBER_2024 }} 24 | run: | 25 | echo "Changes detected. Workflow Triggered!" 26 | curl -X POST \ 27 | -H "Accept: application/vnd.github+json" \ 28 | -H "Authorization: Bearer $GITHUB_TOKEN" \ 29 | https://api.github.com/repos/yashksaini-coder/Update-Leetcode-Gist/actions/workflows/main.yml/dispatches \ 30 | -d '{"ref":"main"}' 31 | -------------------------------------------------------------------------------- /1371-find-the-longest-substring-containing-vowels-in-even-counts/find-the-longest-substring-containing-vowels-in-even-counts.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | class Solution { 4 | public int findTheLongestSubstring(String s) { 5 | int n = s.length(); 6 | int mask = 0; 7 | int maxLength = 0; 8 | HashMap m = new HashMap<>(); 9 | m.put(0, -1); 10 | 11 | for (int i = 0; i < n; i++) { 12 | char c = s.charAt(i); 13 | if (c == 'a') mask ^= (1 << 0); 14 | else if (c == 'e') mask ^= (1 << 1); 15 | else if (c == 'i') mask ^= (1 << 2); 16 | else if (c == 'o') mask ^= (1 << 3); 17 | else if (c == 'u') mask ^= (1 << 4); 18 | 19 | if (m.containsKey(mask)) { 20 | maxLength = Math.max(maxLength, i - m.get(mask)); 21 | } else { 22 | m.put(mask, i); 23 | } 24 | } 25 | return maxLength; 26 | } 27 | } -------------------------------------------------------------------------------- /179-largest-number/README.md: -------------------------------------------------------------------------------- 1 |

Largest Number

Difficulty: Medium

Given a list of non-negative integers nums, arrange them such that they form the largest number and return it.

2 | 3 |

Since the result may be very large, so you need to return a string instead of an integer.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
 9 | Input: nums = [10,2]
10 | Output: "210"
11 | 
12 | 13 |

Example 2:

14 | 15 |
16 | Input: nums = [3,30,34,5,9]
17 | Output: "9534330"
18 | 
19 | 20 |

 

21 |

Constraints:

22 | 23 |
    24 |
  • 1 <= nums.length <= 100
  • 25 |
  • 0 <= nums[i] <= 109
  • 26 |
27 | -------------------------------------------------------------------------------- /scripts/node_modules/node-fetch/src/errors/fetch-error.js: -------------------------------------------------------------------------------- 1 | 2 | import {FetchBaseError} from './base.js'; 3 | 4 | /** 5 | * @typedef {{ address?: string, code: string, dest?: string, errno: number, info?: object, message: string, path?: string, port?: number, syscall: string}} SystemError 6 | */ 7 | 8 | /** 9 | * FetchError interface for operational errors 10 | */ 11 | export class FetchError extends FetchBaseError { 12 | /** 13 | * @param {string} message - Error message for human 14 | * @param {string} [type] - Error type for machine 15 | * @param {SystemError} [systemError] - For Node.js system error 16 | */ 17 | constructor(message, type, systemError) { 18 | super(message, type); 19 | // When err.type is `system`, err.erroredSysCall contains system error and err.code contains system error code 20 | if (systemError) { 21 | // eslint-disable-next-line no-multi-assign 22 | this.code = this.errno = systemError.code; 23 | this.erroredSysCall = systemError.syscall; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /214-shortest-palindrome/README.md: -------------------------------------------------------------------------------- 1 |

Shortest Palindrome

Difficulty: Hard

You are given a string s. You can convert s to a palindrome by adding characters in front of it.

2 | 3 |

Return the shortest palindrome you can find by performing this transformation.

4 | 5 |

 

6 |

Example 1:

7 |
Input: s = "aacecaaa"
 8 | Output: "aaacecaaa"
 9 | 

Example 2:

10 |
Input: s = "abcd"
11 | Output: "dcbabcd"
12 | 
13 |

 

14 |

Constraints:

15 | 16 |
    17 |
  • 0 <= s.length <= 5 * 104
  • 18 |
  • s consists of lowercase English letters only.
  • 19 |
20 | -------------------------------------------------------------------------------- /241-different-ways-to-add-parentheses/different-ways-to-add-parentheses.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public List diffWaysToCompute(String expression) { 3 | List res = new ArrayList<>(); 4 | for (int i=0; i s1 = diffWaysToCompute(expression.substring(0, i)); 8 | List s2 = diffWaysToCompute(expression.substring(i + 1)); 9 | for (int a : s1) { 10 | for (int b : s2) { 11 | if (operator == '+') res.add(a + b); 12 | else if (operator == '-') res.add(a - b); 13 | else if (operator == '*') res.add(a * b); 14 | } 15 | } 16 | } 17 | } 18 | if (res.isEmpty()) res.add(Integer.parseInt(expression)); 19 | return res; 20 | } 21 | } -------------------------------------------------------------------------------- /1367-linked-list-in-binary-tree/linked-list-in-binary-tree.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | boolean a = false; 3 | public boolean isSubPath(ListNode head, TreeNode root) { 4 | help(head,root); 5 | return a; 6 | } 7 | public void help(ListNode head,TreeNode root){ 8 | if(head == null){ 9 | a=true; 10 | return; 11 | } 12 | if(root == null){ 13 | return; 14 | } 15 | if(head.val==root.val){ 16 | helper(head.next,root.left); 17 | helper(head.next,root.right); 18 | } 19 | help(head,root.left); 20 | help(head,root.right); 21 | } 22 | public void helper(ListNode head,TreeNode root){ 23 | if(head == null){ 24 | a=true; 25 | return; 26 | } 27 | if(root == null){ 28 | return; 29 | } 30 | if(head.val==root.val){ 31 | helper(head.next,root.left); 32 | helper(head.next,root.right); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /539-minimum-time-difference/minimum-time-difference.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | 3 | public int findMinDifference(List timePoints) { 4 | // convert input to minutes 5 | int[] minutes = new int[timePoints.size()]; 6 | for (int i = 0; i < timePoints.size(); i++) { 7 | String time = timePoints.get(i); 8 | int h = Integer.parseInt(time.substring(0, 2)); 9 | int m = Integer.parseInt(time.substring(3)); 10 | minutes[i] = h * 60 + m; 11 | } 12 | 13 | // sort times in ascending order 14 | Arrays.sort(minutes); 15 | 16 | // find minimum difference across adjacent elements 17 | int ans = Integer.MAX_VALUE; 18 | for (int i = 0; i < minutes.length - 1; i++) { 19 | ans = Math.min(ans, minutes[i + 1] - minutes[i]); 20 | } 21 | 22 | // consider difference between last and first element 23 | return Math.min( 24 | ans, 25 | 24 * 60 - minutes[minutes.length - 1] + minutes[0] 26 | ); 27 | } 28 | } -------------------------------------------------------------------------------- /725-split-linked-list-in-parts/split-linked-list-in-parts.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public ListNode[] splitListToParts(ListNode head, int k) { 3 | int n = 0; 4 | ListNode curr = head; 5 | while (curr != null) { 6 | n++; 7 | curr = curr.next; 8 | } 9 | 10 | int base = n / k; 11 | int extra = n % k; 12 | 13 | ListNode[] res = new ListNode[k]; 14 | curr = head; 15 | for (int i = 0; i < k; i++) { 16 | ListNode part_head = curr; 17 | int part_size = base + (extra > 0 ? 1 : 0); 18 | extra--; 19 | for (int j = 0; j < part_size - 1 && curr != null; j++) { 20 | curr = curr.next; 21 | } 22 | if (curr != null) { 23 | ListNode next_part = curr.next; 24 | curr.next = null; 25 | curr = next_part; 26 | } 27 | 28 | res[i] = part_head; 29 | } 30 | 31 | return res; 32 | } 33 | } -------------------------------------------------------------------------------- /440-k-th-smallest-in-lexicographical-order/README.md: -------------------------------------------------------------------------------- 1 |

K-th Smallest in Lexicographical Order

Difficulty: Hard

Given two integers n and k, return the kth lexicographically smallest integer in the range [1, n].

2 | 3 |

 

4 |

Example 1:

5 | 6 |
 7 | Input: n = 13, k = 2
 8 | Output: 10
 9 | Explanation: The lexicographical order is [1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9], so the second smallest number is 10.
10 | 
11 | 12 |

Example 2:

13 | 14 |
15 | Input: n = 1, k = 1
16 | Output: 1
17 | 
18 | 19 |

 

20 |

Constraints:

21 | 22 |
    23 |
  • 1 <= k <= n <= 109
  • 24 |
25 | -------------------------------------------------------------------------------- /.github/workflows/readme.yml: -------------------------------------------------------------------------------- 1 | name: Generate Table of Contents 2 | 3 | on: 4 | push: 5 | branches: ["main"] 6 | workflow_dispatch: 7 | schedule: 8 | - cron: '0 0 * * *' # Runs at 00:00 UTC every day 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - name: Checkout code 16 | uses: actions/checkout@v2 17 | 18 | - name: Set up Node.js 19 | uses: actions/setup-node@v2 20 | with: 21 | node-version: "20" 22 | 23 | - name: Install dependencies 24 | run: npm install 25 | working-directory: scripts 26 | 27 | - name: Run index.js 28 | run: node index.js 29 | working-directory: scripts 30 | 31 | - name: Commit and push if changed 32 | run: | 33 | git config --global user.email "actions@github.com" 34 | git config --global user.name "GitHub Actions" 35 | git add . 36 | git diff --quiet && git diff --staged --quiet || (git commit -m "Update README with table of contents" && git push) 37 | working-directory: ${{ github.workspace }} 38 | -------------------------------------------------------------------------------- /440-k-th-smallest-in-lexicographical-order/k-th-smallest-in-lexicographical-order.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int findKthNumber(int n, int k) { 3 | int currentPrefix = 1; 4 | k--; // Decrement k to handle zero-based indexing 5 | 6 | while (k > 0) { 7 | int count = countNumbersWithPrefix(currentPrefix, n); 8 | if (k >= count) { 9 | currentPrefix++; // Move to the next prefix 10 | k -= count; 11 | } else { 12 | currentPrefix *= 10; // Go deeper in the current prefix 13 | k--; 14 | } 15 | } 16 | 17 | return currentPrefix; 18 | } 19 | 20 | private int countNumbersWithPrefix(int prefix, int n) { 21 | long firstNumber = prefix, nextNumber = prefix + 1; 22 | int totalCount = 0; 23 | 24 | while (firstNumber <= n) { 25 | totalCount += Math.min(n + 1, nextNumber) - firstNumber; 26 | firstNumber *= 10; 27 | nextNumber *= 10; 28 | } 29 | 30 | return totalCount; 31 | } 32 | } -------------------------------------------------------------------------------- /432-all-oone-data-structure/all-oone-data-structure.java: -------------------------------------------------------------------------------- 1 | class AllOne { 2 | private Map count; 3 | private TreeSet> set; 4 | 5 | public AllOne() { 6 | count = new HashMap<>(); 7 | set = new TreeSet<>((a, b) -> a.getKey().equals(b.getKey()) ? a.getValue().compareTo(b.getValue()) : a.getKey() - b.getKey()); 8 | } 9 | 10 | public void inc(String key) { 11 | int n = count.getOrDefault(key, 0); 12 | count.put(key, n + 1); 13 | set.remove(new Pair<>(n, key)); 14 | set.add(new Pair<>(n + 1, key)); 15 | } 16 | 17 | public void dec(String key) { 18 | int n = count.get(key); 19 | set.remove(new Pair<>(n, key)); 20 | if (n == 1) count.remove(key); 21 | else { 22 | count.put(key, n - 1); 23 | set.add(new Pair<>(n - 1, key)); 24 | } 25 | } 26 | 27 | public String getMaxKey() { 28 | return set.isEmpty() ? "" : set.last().getValue(); 29 | } 30 | 31 | public String getMinKey() { 32 | return set.isEmpty() ? "" : set.first().getValue(); 33 | } 34 | } -------------------------------------------------------------------------------- /2707-extra-characters-in-a-string/extra-characters-in-a-string.java: -------------------------------------------------------------------------------- 1 | import java.util.HashSet; 2 | import java.util.Set; 3 | 4 | class Solution { 5 | public int minExtraChar(String s, String[] dictionary) { 6 | Set dict = new HashSet<>(); 7 | for (String word : dictionary) { 8 | dict.add(word); 9 | } 10 | int n = s.length(); 11 | int[] dp = new int[n + 1]; 12 | 13 | // Initialize dp array 14 | for (int i = 0; i <= n; i++) { 15 | dp[i] = n; // Maximum extra characters possible 16 | } 17 | dp[0] = 0; // No extra characters needed for an empty string 18 | 19 | for (int i = 1; i <= n; i++) { 20 | for (int j = 0; j < i; j++) { 21 | String sub = s.substring(j, i); 22 | if (dict.contains(sub)) { 23 | dp[i] = Math.min(dp[i], dp[j]); // No extra characters if sub is in dictionary 24 | } 25 | } 26 | dp[i] = Math.min(dp[i], dp[i - 1] + 1); // Extra character if we don't use dp[i-1] 27 | } 28 | 29 | return dp[n]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Yash Kumar Saini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /scripts/node_modules/fetch-blob/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 David Frank 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jimmy Wärting 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /scripts/node_modules/formdata-polyfill/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Jimmy Karl Roland Wärting 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /scripts/node_modules/node-fetch/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 - 2020 Node Fetch Team 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /3043-find-the-length-of-the-longest-common-prefix/find-the-length-of-the-longest-common-prefix.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | class Solution { 4 | public int longestCommonPrefix(int[] arr1, int[] arr2) { 5 | HashMap prefixMap = new HashMap<>(); 6 | 7 | // Step 1: Build the prefix map for arr1 8 | for (int num : arr1) { 9 | String strNum = Integer.toString(num); 10 | String prefix = ""; 11 | for (char ch : strNum.toCharArray()) { 12 | prefix += ch; 13 | prefixMap.put(prefix, prefixMap.getOrDefault(prefix, 0) + 1); 14 | } 15 | } 16 | 17 | int maxLength = 0; 18 | 19 | // Step 2: Check for common prefixes in arr2 20 | for (int num : arr2) { 21 | String strNum = Integer.toString(num); 22 | String prefix = ""; 23 | for (char ch : strNum.toCharArray()) { 24 | prefix += ch; 25 | if (prefixMap.containsKey(prefix)) { 26 | maxLength = Math.max(maxLength, prefix.length()); 27 | } 28 | } 29 | } 30 | 31 | return maxLength; 32 | } 33 | } -------------------------------------------------------------------------------- /scripts/node_modules/web-streams-polyfill/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2024 Mattias Buelens 4 | Copyright (c) 2016 Diwank Singh Tomer 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /874-walking-robot-simulation/walking-robot-simulation.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int robotSim(int[] commands, int[][] obstacles) { 3 | Set obstacleSet = new HashSet<>(); 4 | for (int[] obstacle : obstacles) { 5 | obstacleSet.add(obstacle[0] + "," + obstacle[1]); 6 | } 7 | 8 | int[][] directions = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; // North, East, South, West 9 | int x = 0, y = 0, direction = 0, maxDistance = 0; 10 | 11 | for (int command : commands) { 12 | if (command == -1) { 13 | direction = (direction + 1) % 4; 14 | } else if (command == -2) { 15 | direction = (direction + 3) % 4; 16 | } else { 17 | for (int i = 0; i < command; i++) { 18 | int newX = x + directions[direction][0]; 19 | int newY = y + directions[direction][1]; 20 | if (!obstacleSet.contains(newX + "," + newY)) { 21 | x = newX; 22 | y = newY; 23 | maxDistance = Math.max(maxDistance, x * x + y * y); 24 | } else { 25 | break; 26 | } 27 | } 28 | } 29 | } 30 | 31 | return maxDistance; 32 | } 33 | } -------------------------------------------------------------------------------- /scripts/node_modules/web-streams-polyfill/dist/types/ts3.6/polyfill.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | import type { ReadableStreamAsyncIterator, ReadableStreamIteratorOptions } from './ponyfill'; 5 | 6 | export * from './ponyfill'; 7 | 8 | declare global { 9 | interface ReadableStream extends AsyncIterable { 10 | /** 11 | * Asynchronously iterates over the chunks in the stream's internal queue. 12 | * 13 | * Asynchronously iterating over the stream will lock it, preventing any other consumer from acquiring a reader. 14 | * The lock will be released if the async iterator's {@link ReadableStreamAsyncIterator.return | return()} method 15 | * is called, e.g. by breaking out of the loop. 16 | * 17 | * By default, calling the async iterator's {@link ReadableStreamAsyncIterator.return | return()} method will also 18 | * cancel the stream. To prevent this, use the stream's {@link ReadableStream.values | values()} method, passing 19 | * `true` for the `preventCancel` option. 20 | */ 21 | values(options?: ReadableStreamIteratorOptions): ReadableStreamAsyncIterator; 22 | 23 | /** 24 | * {@inheritDoc ReadableStream.values} 25 | */ 26 | [Symbol.asyncIterator](options?: ReadableStreamIteratorOptions): ReadableStreamAsyncIterator; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /_layouts/default.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | {% include head-custom.html %} 9 | 10 | {% seo %} 11 | 12 | 13 | 14 | 15 |
16 |
17 | 18 |

{{ site.title | default: site.github.repository_name }}

19 |
20 |

{{ site.description | default: site.github.project_tagline }}

21 | 22 |
23 | {% if site.show_downloads %} 24 | Download as .zip 25 | Download as .tar.gz 26 | {% endif %} 27 | View on GitHub 28 |
29 |
30 |
31 | 32 |
33 |
34 | {{ content }} 35 |
36 |
37 | 38 | 39 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527214643.js: -------------------------------------------------------------------------------- 1 | /*! node-domexception. MIT License. Jimmy Wärting */ 2 | 3 | if (!globalThis.DOMException) { 4 | try { 5 | const { MessageChannel } = require('worker_threads'), 6 | port = new MessageChannel().port1, 7 | ab = new ArrayBuffer() 8 | port.postMessage(ab, [ab, ab]) 9 | } catch (err) { 10 | err.constructor.name === 'DOMException' && ( 11 | globalThis.DOMException = err.constructor 12 | ) 13 | } 14 | } 15 | 16 | module.exports = globalThis.DOMException 17 | 18 | 19 | const { MessageChannel } = require('worker_threads') 20 | 21 | async function hello() { 22 | const port = new MessageChannel().port1 23 | const ab = new ArrayBuffer() 24 | port.postMessage(ab, [ab, ab]) 25 | } 26 | 27 | hello().catch(err => { 28 | console.assert(err.name === 'DataCloneError') 29 | console.assert(err.code === 25) 30 | console.assert(err instanceof DOMException) 31 | }) 32 | 33 | const e1 = new DOMException('Something went wrong', 'BadThingsError') 34 | console.assert(e1.name === 'BadThingsError') 35 | console.assert(e1.code === 0) 36 | 37 | const e2 = new DOMException('Another exciting error message', 'NoModificationAllowedError') 38 | console.assert(e2.name === 'NoModificationAllowedError') 39 | console.assert(e2.code === 7) 40 | 41 | console.assert(DOMException.INUSE_ATTRIBUTE_ERR === 10) 42 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/index_20210527214654.js: -------------------------------------------------------------------------------- 1 | /*! node-domexception. MIT License. Jimmy Wärting */ 2 | 3 | if (!globalThis.DOMException) { 4 | try { 5 | const { MessageChannel } = require('worker_threads'), 6 | port = new MessageChannel().port1, 7 | ab = new ArrayBuffer() 8 | port.postMessage(ab, [ab, ab]) 9 | } catch (err) { 10 | err.constructor.name === 'DOMException' && ( 11 | globalThis.DOMException = err.constructor 12 | ) 13 | } 14 | } 15 | 16 | module.exports = globalThis.DOMException 17 | 18 | 19 | const { MessageChannel } = require('worker_threads') 20 | 21 | async function hello() { 22 | const port = new MessageChannel().port1 23 | const ab = new ArrayBuffer() 24 | port.postMessage(ab, [ab, ab]) 25 | } 26 | 27 | hello().catch(err => { 28 | console.assert(err.name === 'DataCloneError') 29 | console.assert(err.code === 21) 30 | console.assert(err instanceof DOMException) 31 | }) 32 | 33 | const e1 = new DOMException('Something went wrong', 'BadThingsError') 34 | console.assert(e1.name === 'BadThingsError') 35 | console.assert(e1.code === 0) 36 | 37 | const e2 = new DOMException('Another exciting error message', 'NoModificationAllowedError') 38 | console.assert(e2.name === 'NoModificationAllowedError') 39 | console.assert(e2.code === 7) 40 | 41 | console.assert(DOMException.INUSE_ATTRIBUTE_ERR === 10) 42 | -------------------------------------------------------------------------------- /scripts/node_modules/web-streams-polyfill/dist/types/polyfill.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | import { ReadableStreamAsyncIterator, ReadableStreamIteratorOptions } from './ponyfill'; 4 | export * from './ponyfill'; 5 | declare global { 6 | interface ReadableStream extends AsyncIterable { 7 | /** 8 | * Asynchronously iterates over the chunks in the stream's internal queue. 9 | * 10 | * Asynchronously iterating over the stream will lock it, preventing any other consumer from acquiring a reader. 11 | * The lock will be released if the async iterator's {@link ReadableStreamAsyncIterator.return | return()} method 12 | * is called, e.g. by breaking out of the loop. 13 | * 14 | * By default, calling the async iterator's {@link ReadableStreamAsyncIterator.return | return()} method will also 15 | * cancel the stream. To prevent this, use the stream's {@link ReadableStream.values | values()} method, passing 16 | * `true` for the `preventCancel` option. 17 | */ 18 | values(options?: ReadableStreamIteratorOptions): ReadableStreamAsyncIterator; 19 | /** 20 | * {@inheritDoc ReadableStream.values} 21 | */ 22 | [Symbol.asyncIterator](options?: ReadableStreamIteratorOptions): ReadableStreamAsyncIterator; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /scripts/node_modules/fetch-blob/file.js: -------------------------------------------------------------------------------- 1 | import Blob from './index.js' 2 | 3 | const _File = class File extends Blob { 4 | #lastModified = 0 5 | #name = '' 6 | 7 | /** 8 | * @param {*[]} fileBits 9 | * @param {string} fileName 10 | * @param {{lastModified?: number, type?: string}} options 11 | */// @ts-ignore 12 | constructor (fileBits, fileName, options = {}) { 13 | if (arguments.length < 2) { 14 | throw new TypeError(`Failed to construct 'File': 2 arguments required, but only ${arguments.length} present.`) 15 | } 16 | super(fileBits, options) 17 | 18 | if (options === null) options = {} 19 | 20 | // Simulate WebIDL type casting for NaN value in lastModified option. 21 | const lastModified = options.lastModified === undefined ? Date.now() : Number(options.lastModified) 22 | if (!Number.isNaN(lastModified)) { 23 | this.#lastModified = lastModified 24 | } 25 | 26 | this.#name = String(fileName) 27 | } 28 | 29 | get name () { 30 | return this.#name 31 | } 32 | 33 | get lastModified () { 34 | return this.#lastModified 35 | } 36 | 37 | get [Symbol.toStringTag] () { 38 | return 'File' 39 | } 40 | 41 | static [Symbol.hasInstance] (object) { 42 | return !!object && object instanceof Blob && 43 | /^(File)$/.test(object[Symbol.toStringTag]) 44 | } 45 | } 46 | 47 | /** @type {typeof globalThis.File} */// @ts-ignore 48 | export const File = _File 49 | export default File 50 | -------------------------------------------------------------------------------- /scripts/node_modules/formdata-polyfill/formdata-to-blob.js: -------------------------------------------------------------------------------- 1 | /*! formdata-polyfill. MIT License. Jimmy Wärting */ 2 | 3 | const escape = (str, filename) => 4 | (filename ? str : str.replace(/\r?\n|\r/g, '\r\n')) 5 | .replace(/\n/g, '%0A') 6 | .replace(/\r/g, '%0D') 7 | .replace(/"/g, '%22') 8 | 9 | /** 10 | * pure function to convert any formData instance to a Blob 11 | * instances synchronous without reading all of the files 12 | * 13 | * @param {FormData|*} formData an instance of a formData Class 14 | * @param {Blob|*} [BlobClass=Blob] the Blob class to use when constructing it 15 | */ 16 | export function formDataToBlob (formData, BlobClass = Blob) { 17 | const boundary = ('----formdata-polyfill-' + Math.random()) 18 | const chunks = [] 19 | const prefix = `--${boundary}\r\nContent-Disposition: form-data; name="` 20 | 21 | for (let [name, value] of formData) { 22 | if (typeof value === 'string') { 23 | chunks.push(prefix + escape(name) + `"\r\n\r\n${value.replace(/\r(?!\n)|(?=12.20.0" 27 | }, 28 | "keywords": [ 29 | "formdata", 30 | "fetch", 31 | "node-fetch", 32 | "html5", 33 | "browser", 34 | "polyfill" 35 | ], 36 | "author": "Jimmy Wärting", 37 | "license": "MIT", 38 | "bugs": { 39 | "url": "https://github.com/jimmywarting/FormData/issues" 40 | }, 41 | "homepage": "https://github.com/jimmywarting/FormData#readme", 42 | "dependencies": { 43 | "fetch-blob": "^3.1.2" 44 | }, 45 | "devDependencies": { 46 | "@types/google-closure-compiler": "^0.0.19", 47 | "@types/node": "^16.7.10", 48 | "google-closure-compiler": "^20210808.0.0" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /.github/workflows/jekyll-gh-pages.yml: -------------------------------------------------------------------------------- 1 | # Sample workflow for building and deploying a Jekyll site to GitHub Pages 2 | name: Deploy Jekyll with GitHub Pages dependencies preinstalled 3 | 4 | on: 5 | # Runs on pushes targeting the default branch 6 | push: 7 | branches: ["main"] 8 | 9 | # Allows you to run this workflow manually from the Actions tab 10 | workflow_dispatch: 11 | 12 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages 13 | permissions: 14 | contents: read 15 | pages: write 16 | id-token: write 17 | 18 | # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. 19 | # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. 20 | concurrency: 21 | group: "pages" 22 | cancel-in-progress: false 23 | 24 | jobs: 25 | # Build job 26 | build: 27 | runs-on: ubuntu-latest 28 | steps: 29 | - name: Checkout 30 | uses: actions/checkout@v4 31 | - name: Setup Pages 32 | uses: actions/configure-pages@v5 33 | - name: Build with Jekyll 34 | uses: actions/jekyll-build-pages@v1 35 | with: 36 | source: ./ 37 | destination: ./_site 38 | - name: Upload artifact 39 | uses: actions/upload-pages-artifact@v3 40 | 41 | # Deployment job 42 | deploy: 43 | environment: 44 | name: github-pages 45 | url: ${{ steps.deployment.outputs.page_url }} 46 | runs-on: ubuntu-latest 47 | needs: build 48 | steps: 49 | - name: Deploy to GitHub Pages 50 | id: deployment 51 | uses: actions/deploy-pages@v4 52 | -------------------------------------------------------------------------------- /scripts/node_modules/data-uri-to-buffer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "data-uri-to-buffer", 3 | "version": "4.0.1", 4 | "description": "Generate a Buffer instance from a Data URI string", 5 | "type": "module", 6 | "exports": "./dist/index.js", 7 | "main": "./dist/index.js", 8 | "types": "./dist/index.d.ts", 9 | "files": [ 10 | "dist", 11 | "src" 12 | ], 13 | "scripts": { 14 | "build": "tsc", 15 | "test": "jest", 16 | "prepublishOnly": "npm run build" 17 | }, 18 | "repository": { 19 | "type": "git", 20 | "url": "git://github.com/TooTallNate/node-data-uri-to-buffer.git" 21 | }, 22 | "engines": { 23 | "node": ">= 12" 24 | }, 25 | "keywords": [ 26 | "data", 27 | "uri", 28 | "datauri", 29 | "data-uri", 30 | "buffer", 31 | "convert", 32 | "rfc2397", 33 | "2397" 34 | ], 35 | "author": "Nathan Rajlich (http://n8.io/)", 36 | "license": "MIT", 37 | "bugs": { 38 | "url": "https://github.com/TooTallNate/node-data-uri-to-buffer/issues" 39 | }, 40 | "homepage": "https://github.com/TooTallNate/node-data-uri-to-buffer", 41 | "devDependencies": { 42 | "@types/jest": "^27.0.2", 43 | "@types/node": "^12.20.36", 44 | "jest": "^27.3.1", 45 | "ts-jest": "^27.0.7", 46 | "typescript": "^4.4.4" 47 | }, 48 | "jest": { 49 | "preset": "ts-jest", 50 | "globals": { 51 | "ts-jest": { 52 | "diagnostics": false, 53 | "isolatedModules": true 54 | } 55 | }, 56 | "verbose": false, 57 | "testEnvironment": "node", 58 | "testMatch": [ 59 | "/test/**/*.test.ts" 60 | ] 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /241-different-ways-to-add-parentheses/README.md: -------------------------------------------------------------------------------- 1 |

Different Ways to Add Parentheses

Difficulty: Medium

Given a string expression of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. You may return the answer in any order.

2 | 3 |

The test cases are generated such that the output values fit in a 32-bit integer and the number of different results does not exceed 104.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
 9 | Input: expression = "2-1-1"
10 | Output: [0,2]
11 | Explanation:
12 | ((2-1)-1) = 0 
13 | (2-(1-1)) = 2
14 | 
15 | 16 |

Example 2:

17 | 18 |
19 | Input: expression = "2*3-4*5"
20 | Output: [-34,-14,-10,-10,10]
21 | Explanation:
22 | (2*(3-(4*5))) = -34 
23 | ((2*3)-(4*5)) = -14 
24 | ((2*(3-4))*5) = -10 
25 | (2*((3-4)*5)) = -10 
26 | (((2*3)-4)*5) = 10
27 | 
28 | 29 |

 

30 |

Constraints:

31 | 32 |
    33 |
  • 1 <= expression.length <= 20
  • 34 |
  • expression consists of digits and the operator '+', '-', and '*'.
  • 35 |
  • All the integer values in the input expression are in the range [0, 99].
  • 36 |
37 | -------------------------------------------------------------------------------- /scripts/node_modules/data-uri-to-buffer/dist/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,GAAW;IAC1C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QACzB,MAAM,IAAI,SAAS,CAClB,kEAAkE,CAClE,CAAC;KACF;IAED,iBAAiB;IACjB,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAEhC,+DAA+D;IAC/D,MAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACpC,IAAI,UAAU,KAAK,CAAC,CAAC,IAAI,UAAU,IAAI,CAAC,EAAE;QACzC,MAAM,IAAI,SAAS,CAAC,qBAAqB,CAAC,CAAC;KAC3C;IAED,mDAAmD;IACnD,MAAM,IAAI,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAErD,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC;IACrC,IAAI,QAAQ,GAAG,IAAI,CAAC;IACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACrC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;YACzB,MAAM,GAAG,IAAI,CAAC;SACd;aAAM,IAAG,IAAI,CAAC,CAAC,CAAC,EAAE;YAClB,QAAQ,IAAI,IAAM,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5B,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;gBACtC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;aAC/B;SACD;KACD;IACD,oDAAoD;IACpD,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QAChC,QAAQ,IAAI,mBAAmB,CAAC;QAChC,OAAO,GAAG,UAAU,CAAC;KACrB;IAED,4DAA4D;IAC5D,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;IAC7C,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC;IACrD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAe,CAAC;IAEzD,sDAAsD;IACtD,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,MAAM,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAE3B,8BAA8B;IAC9B,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;IAEzB,OAAO,MAAM,CAAC;AACf,CAAC;AAED,eAAe,eAAe,CAAC"} -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/README_20210527213345.md: -------------------------------------------------------------------------------- 1 | # DOMException 2 | An implementation of the DOMException class from NodeJS 3 | 4 | This package implements the [`DOMException`](https://developer.mozilla.org/en-US/docs/Web/API/DOMException) class, from NodeJS itself. (including the legacy codes) 5 | NodeJS has DOMException built in, but it's not globally available, and you can't require/import it from somewhere. 6 | 7 | The only possible way is to use some web-ish tools that have been introduced into NodeJS that throws an error and catch the constructor. 8 | This way you will have the same class that NodeJS has and you can check if the error is a instance of DOMException. 9 | The instanceof check would not have worked with a custom class such as the DOMException provided by domenic which also is much larger in size. 10 | 11 | ```js 12 | import DOMException from 'node-domexception' 13 | import { MessageChannel } from 'worker_threads' 14 | 15 | async function hello() { 16 | const port = new MessageChannel().port1 17 | const ab = new ArrayBuffer() 18 | port.postMessage(ab, [ab, ab]) 19 | } 20 | 21 | hello().catch(err => { 22 | console.assert(err.name === 'DataCloneError') 23 | console.assert(err.code === 25) 24 | console.assert(err instanceof DOMException) 25 | }) 26 | 27 | const e1 = new DOMException('Something went wrong', 'BadThingsError') 28 | console.assert(e1.name === 'BadThingsError') 29 | console.assert(e1.code === 0) 30 | 31 | const e2 = new DOMException('Another exciting error message', 'NoModificationAllowedError') 32 | console.assert(e2.name === 'NoModificationAllowedError') 33 | console.assert(e2.code === 7) 34 | 35 | console.assert(DOMException.INUSE_ATTRIBUTE_ERR === 10) 36 | ``` 37 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/README_20210527213411.md: -------------------------------------------------------------------------------- 1 | # DOMException 2 | An implementation of the DOMException class from NodeJS 3 | 4 | This package implements the [`DOMException`](https://developer.mozilla.org/en-US/docs/Web/API/DOMException) class that comes from NodeJS itself. (including the legacy codes) 5 | NodeJS has DOMException built in, but it's not globally available, and you can't require/import it from somewhere. 6 | 7 | The only possible way is to use some web-ish tools that have been introduced into NodeJS that throws an error and catch the constructor. 8 | This way you will have the same class that NodeJS has and you can check if the error is a instance of DOMException. 9 | The instanceof check would not have worked with a custom class such as the DOMException provided by domenic which also is much larger in size. 10 | 11 | ```js 12 | import DOMException from 'node-domexception' 13 | import { MessageChannel } from 'worker_threads' 14 | 15 | async function hello() { 16 | const port = new MessageChannel().port1 17 | const ab = new ArrayBuffer() 18 | port.postMessage(ab, [ab, ab]) 19 | } 20 | 21 | hello().catch(err => { 22 | console.assert(err.name === 'DataCloneError') 23 | console.assert(err.code === 25) 24 | console.assert(err instanceof DOMException) 25 | }) 26 | 27 | const e1 = new DOMException('Something went wrong', 'BadThingsError') 28 | console.assert(e1.name === 'BadThingsError') 29 | console.assert(e1.code === 0) 30 | 31 | const e2 = new DOMException('Another exciting error message', 'NoModificationAllowedError') 32 | console.assert(e2.name === 'NoModificationAllowedError') 33 | console.assert(e2.code === 7) 34 | 35 | console.assert(DOMException.INUSE_ATTRIBUTE_ERR === 10) 36 | ``` 37 | -------------------------------------------------------------------------------- /2326-spiral-matrix-iv/spiral-matrix-iv.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * public class ListNode { 4 | * int val; 5 | * ListNode next; 6 | * ListNode() {} 7 | * ListNode(int val) { this.val = val; } 8 | * ListNode(int val, ListNode next) { this.val = val; this.next = next; } 9 | * } 10 | */ 11 | class Solution { 12 | public int[][] spiralMatrix(int rows, int columns, ListNode head) { 13 | int[][] matrix = new int[rows][]; 14 | for (int i = 0; i < rows; i++) { 15 | matrix[i] = new int [columns]; 16 | Arrays.fill(matrix[i], -1); 17 | } 18 | 19 | int topRow = 0, bottomRow = rows - 1, leftColumn = 0, rightColumn = columns - 1; 20 | while (head != null) { 21 | 22 | for (int col = leftColumn; col <= rightColumn && head != null; col++) { 23 | matrix[topRow][col] = head.val; 24 | head = head.next; 25 | } 26 | topRow++; 27 | 28 | 29 | for (int row = topRow; row <= bottomRow && head != null; row++) { 30 | matrix[row][rightColumn] = head.val; 31 | head = head.next; 32 | } 33 | rightColumn--; 34 | 35 | 36 | for (int col = rightColumn; col >= leftColumn && head != null; col--) { 37 | matrix[bottomRow][col] = head.val; 38 | head = head.next; 39 | } 40 | bottomRow--; 41 | 42 | 43 | for (int row = bottomRow; row >= topRow && head != null; row--) { 44 | matrix[row][leftColumn] = head.val; 45 | head = head.next; 46 | } 47 | leftColumn++; 48 | } 49 | 50 | return matrix; 51 | } 52 | } -------------------------------------------------------------------------------- /2416-sum-of-prefix-scores-of-strings/sum-of-prefix-scores-of-strings.java: -------------------------------------------------------------------------------- 1 | class Node { 2 | int count = 0; 3 | Node[] list = new Node[26]; 4 | 5 | public boolean containKey(char ch) { 6 | return list[ch - 'a'] != null; 7 | } 8 | 9 | public Node get(char ch) { 10 | return list[ch - 'a']; 11 | } 12 | 13 | public void put(char ch, Node new_node) { 14 | list[ch - 'a'] = new_node; 15 | } 16 | 17 | public void inc(char ch) { 18 | list[ch - 'a'].count++; 19 | } 20 | 21 | public int retCount(char ch) { 22 | return list[ch - 'a'].count; 23 | } 24 | } 25 | 26 | class Solution { 27 | private Node root; 28 | 29 | public Solution() { 30 | root = new Node(); 31 | } 32 | 33 | public void insert(String word) { 34 | Node node = root; 35 | for (char ch : word.toCharArray()) { 36 | if (!node.containKey(ch)) { 37 | node.put(ch, new Node()); 38 | } 39 | node.inc(ch); 40 | node = node.get(ch); 41 | } 42 | } 43 | 44 | public int search(String word) { 45 | Node node = root; 46 | int preCount = 0; 47 | for (char ch : word.toCharArray()) { 48 | preCount += node.retCount(ch); 49 | node = node.get(ch); 50 | } 51 | return preCount; 52 | } 53 | 54 | public int[] sumPrefixScores(String[] words) { 55 | // This problem can be solved using the trie data structure 56 | for (String word : words) { 57 | insert(word); 58 | } 59 | int n = words.length; 60 | int[] res = new int[n]; 61 | for (int i = 0; i < n; i++) { 62 | res[i] = search(words[i]); 63 | } 64 | return res; 65 | } 66 | } -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/README_20210527213803.md: -------------------------------------------------------------------------------- 1 | # DOMException 2 | An implementation of the DOMException class from NodeJS 3 | 4 | This package exposes the [`DOMException`](https://developer.mozilla.org/en-US/docs/Web/API/DOMException) class that comes from NodeJS itself. (including all of the deprecated legacy codes) 5 | NodeJS has it built in, but it's not globally available, and you can't require/import it from somewhere. 6 | 7 | The only possible way is to use some web-ish tools that have been introduced into NodeJS that throws an error and catch the constructor. 8 | This way you will have the same class that NodeJS has and you can check if the error is a instance of DOMException. 9 | The instanceof check would not have worked with a custom class such as the DOMException provided by domenic which also is much larger in size since it has to re-construct the hole class from the ground up. 10 | 11 | ```js 12 | import DOMException from 'node-domexception' 13 | import { MessageChannel } from 'worker_threads' 14 | 15 | async function hello() { 16 | const port = new MessageChannel().port1 17 | const ab = new ArrayBuffer() 18 | port.postMessage(ab, [ab, ab]) 19 | } 20 | 21 | hello().catch(err => { 22 | console.assert(err.name === 'DataCloneError') 23 | console.assert(err.code === 25) 24 | console.assert(err instanceof DOMException) 25 | }) 26 | 27 | const e1 = new DOMException('Something went wrong', 'BadThingsError') 28 | console.assert(e1.name === 'BadThingsError') 29 | console.assert(e1.code === 0) 30 | 31 | const e2 = new DOMException('Another exciting error message', 'NoModificationAllowedError') 32 | console.assert(e2.name === 'NoModificationAllowedError') 33 | console.assert(e2.code === 7) 34 | 35 | console.assert(DOMException.INUSE_ATTRIBUTE_ERR === 10) 36 | ``` 37 | -------------------------------------------------------------------------------- /scripts/node_modules/fetch-blob/streams.cjs: -------------------------------------------------------------------------------- 1 | /* c8 ignore start */ 2 | // 64 KiB (same size chrome slice theirs blob into Uint8array's) 3 | const POOL_SIZE = 65536 4 | 5 | if (!globalThis.ReadableStream) { 6 | // `node:stream/web` got introduced in v16.5.0 as experimental 7 | // and it's preferred over the polyfilled version. So we also 8 | // suppress the warning that gets emitted by NodeJS for using it. 9 | try { 10 | const process = require('node:process') 11 | const { emitWarning } = process 12 | try { 13 | process.emitWarning = () => {} 14 | Object.assign(globalThis, require('node:stream/web')) 15 | process.emitWarning = emitWarning 16 | } catch (error) { 17 | process.emitWarning = emitWarning 18 | throw error 19 | } 20 | } catch (error) { 21 | // fallback to polyfill implementation 22 | Object.assign(globalThis, require('web-streams-polyfill/dist/ponyfill.es2018.js')) 23 | } 24 | } 25 | 26 | try { 27 | // Don't use node: prefix for this, require+node: is not supported until node v14.14 28 | // Only `import()` can use prefix in 12.20 and later 29 | const { Blob } = require('buffer') 30 | if (Blob && !Blob.prototype.stream) { 31 | Blob.prototype.stream = function name (params) { 32 | let position = 0 33 | const blob = this 34 | 35 | return new ReadableStream({ 36 | type: 'bytes', 37 | async pull (ctrl) { 38 | const chunk = blob.slice(position, Math.min(blob.size, position + POOL_SIZE)) 39 | const buffer = await chunk.arrayBuffer() 40 | position += buffer.byteLength 41 | ctrl.enqueue(new Uint8Array(buffer)) 42 | 43 | if (position === blob.size) { 44 | ctrl.close() 45 | } 46 | } 47 | }) 48 | } 49 | } 50 | } catch (error) {} 51 | /* c8 ignore end */ 52 | -------------------------------------------------------------------------------- /LeetSync2-Metadata.txt: -------------------------------------------------------------------------------- 1 | 1894-find-the-student-that-will-replace-the-chalk|Medium|1725215400000 2 | 1945-sum-of-digits-of-string-after-convert|Easy|1725301800000 3 | 874-walking-robot-simulation|Medium|1725388200000 4 | 2028-find-missing-observations|Medium|1725474600000 5 | 3217-delete-nodes-from-linked-list-present-in-array|Medium|1725561000000 6 | 1367-linked-list-in-binary-tree|Medium|1725647400000 7 | 725-split-linked-list-in-parts|Medium|1725733800000 8 | 2326-spiral-matrix-iv|Medium|1725820200000 9 | 2807-insert-greatest-common-divisors-in-linked-list|Medium|1725906600000 10 | 2220-minimum-bit-flips-to-convert-number|Easy|1725993000000 11 | 1684-count-the-number-of-consistent-strings|Easy|1726079400000 12 | 1310-xor-queries-of-a-subarray|Medium|1726165800000 13 | 2419-longest-subarray-with-maximum-bitwise-and|Medium|1726252200000 14 | 1371-find-the-longest-substring-containing-vowels-in-even-counts|Medium|1726338600000 15 | 539-minimum-time-difference|Medium|1726425000000 16 | 884-uncommon-words-from-two-sentences|Easy|1726511400000 17 | 179-largest-number|Medium|1726597800000 18 | 241-different-ways-to-add-parentheses|Medium|1726684200000 19 | 214-shortest-palindrome|Hard|1726770600000 20 | 386-lexicographical-numbers|Medium|1726857000000 21 | 440-k-th-smallest-in-lexicographical-order|Hard|1726943400000 22 | 2707-extra-characters-in-a-string|Medium|1727029800000 23 | 3043-find-the-length-of-the-longest-common-prefix|Medium|1727116200000 24 | 2416-sum-of-prefix-scores-of-strings|Hard|1727202600000 25 | 729-my-calendar-i|Medium|1727289000000 26 | 731-my-calendar-ii|Medium|1727375400000 27 | 641-design-circular-deque|Medium|1727461800000 28 | 432-all-oone-data-structure|Hard|1727548200000 29 | 1381-design-a-stack-with-increment-operation|Medium|1727634600000 30 | 2938-separate-black-and-white-balls|Medium|1728930600000 31 | 3163-string-compression-iii|Medium|1730658600000 32 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/README_20210527212714.md: -------------------------------------------------------------------------------- 1 | # DOMException 2 | An implementation of the DOMException class from NodeJS 3 | 4 | This package implements the [`DOMException`](https://developer.mozilla.org/en-US/docs/Web/API/DOMException) class, from NodeJS itself. 5 | NodeJS has DOMException built in, but it's not globally available, and you can't require/import it from somewhere. 6 | 7 | The only possible way is to use some web-ish tools that have been introduced into NodeJS that throws an error and catch the constructor. 8 | This way you will have the same class that NodeJS has and you can check if the error is a instance of DOMException. 9 | The instanceof check would not have worked with a custom class such as the DOMexception provided by domenic which also is much larger in size. 10 | 11 | ```js 12 | import DOMException from 'node-domexception' 13 | 14 | hello().catch(err => { 15 | if (err instanceof DOMException) { 16 | ... 17 | } 18 | }) 19 | 20 | const e1 = new DOMException("Something went wrong", "BadThingsError"); 21 | console.assert(e1.name === "BadThingsError"); 22 | console.assert(e1.code === 0); 23 | 24 | const e2 = new DOMException("Another exciting error message", "NoModificationAllowedError"); 25 | console.assert(e2.name === "NoModificationAllowedError"); 26 | console.assert(e2.code === 7); 27 | 28 | console.assert(DOMException.INUSE_ATTRIBUTE_ERR === 10); 29 | ``` 30 | 31 | ## APIs 32 | 33 | This package exposes two flavors of the `DOMException` interface depending on the imported module. 34 | 35 | ### `domexception` module 36 | 37 | This module default-exports the `DOMException` interface constructor. 38 | 39 | ### `domexception/webidl2js-wrapper` module 40 | 41 | This module exports the `DOMException` [interface wrapper API](https://github.com/jsdom/webidl2js#for-interfaces) generated by [webidl2js](https://github.com/jsdom/webidl2js). 42 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/README_20210527214323.md: -------------------------------------------------------------------------------- 1 | # DOMException 2 | An implementation of the DOMException class from NodeJS 3 | 4 | This package exposes the [`DOMException`](https://developer.mozilla.org/en-US/docs/Web/API/DOMException) class that comes from NodeJS itself. (including all of the deprecated legacy codes) 5 | NodeJS has it built in, but it's not globally available, and you can't require/import it from somewhere. 6 | 7 | The only possible way is to use some web-ish tools that have been introduced into NodeJS that throws an error and catch the constructor. 8 | This way you will have the same class that NodeJS has and you can check if the error is a instance of DOMException. 9 | The instanceof check would not have worked with a custom class such as the DOMException provided by domenic which also is much larger in size since it has to re-construct the hole class from the ground up. 10 | 11 | (plz don't depend on this package in any other environment other than node >=10.5) 12 | 13 | ```js 14 | import DOMException from 'node-domexception' 15 | import { MessageChannel } from 'worker_threads' 16 | 17 | async function hello() { 18 | const port = new MessageChannel().port1 19 | const ab = new ArrayBuffer() 20 | port.postMessage(ab, [ab, ab]) 21 | } 22 | 23 | hello().catch(err => { 24 | console.assert(err.name === 'DataCloneError') 25 | console.assert(err.code === 25) 26 | console.assert(err instanceof DOMException) 27 | }) 28 | 29 | const e1 = new DOMException('Something went wrong', 'BadThingsError') 30 | console.assert(e1.name === 'BadThingsError') 31 | console.assert(e1.code === 0) 32 | 33 | const e2 = new DOMException('Another exciting error message', 'NoModificationAllowedError') 34 | console.assert(e2.name === 'NoModificationAllowedError') 35 | console.assert(e2.code === 7) 36 | 37 | console.assert(DOMException.INUSE_ATTRIBUTE_ERR === 10) 38 | ``` 39 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/.history/README_20210527214408.md: -------------------------------------------------------------------------------- 1 | # DOMException 2 | An implementation of the DOMException class from NodeJS 3 | 4 | This package exposes the [`DOMException`](https://developer.mozilla.org/en-US/docs/Web/API/DOMException) class that comes from NodeJS itself. (including all of the deprecated legacy codes) 5 | NodeJS has it built in, but it's not globally available, and you can't require/import it from somewhere. 6 | 7 | The only possible way is to use some web-ish tools that have been introduced into NodeJS that throws an error and catch the constructor. 8 | This way you will have the same class that NodeJS has and you can check if the error is a instance of DOMException. 9 | The instanceof check would not have worked with a custom class such as the DOMException provided by domenic which also is much larger in size since it has to re-construct the hole class from the ground up. 10 | 11 | (plz don't depend on this package in any other environment other than node >=10.5) 12 | 13 | ```js 14 | import DOMException from 'node-domexception' 15 | import { MessageChannel } from 'worker_threads' 16 | 17 | async function hello() { 18 | const port = new MessageChannel().port1 19 | const ab = new ArrayBuffer() 20 | port.postMessage(ab, [ab, ab]) 21 | } 22 | 23 | hello().catch(err => { 24 | console.assert(err.name === 'DataCloneError') 25 | console.assert(err.code === 25) 26 | console.assert(err instanceof DOMException) 27 | }) 28 | 29 | const e1 = new DOMException('Something went wrong', 'BadThingsError') 30 | console.assert(e1.name === 'BadThingsError') 31 | console.assert(e1.code === 0) 32 | 33 | const e2 = new DOMException('Another exciting error message', 'NoModificationAllowedError') 34 | console.assert(e2.name === 'NoModificationAllowedError') 35 | console.assert(e2.code === 7) 36 | 37 | console.assert(DOMException.INUSE_ATTRIBUTE_ERR === 10) 38 | ``` 39 | -------------------------------------------------------------------------------- /scripts/node_modules/fetch-blob/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fetch-blob", 3 | "version": "3.2.0", 4 | "description": "Blob & File implementation in Node.js, originally from node-fetch.", 5 | "main": "index.js", 6 | "type": "module", 7 | "files": [ 8 | "from.js", 9 | "file.js", 10 | "file.d.ts", 11 | "index.js", 12 | "index.d.ts", 13 | "from.d.ts", 14 | "streams.cjs" 15 | ], 16 | "scripts": { 17 | "test": "node --experimental-loader ./test/http-loader.js ./test/test-wpt-in-node.js", 18 | "report": "c8 --reporter json --reporter text npm run test", 19 | "coverage": "npm run report && codecov -f coverage/coverage-final.json", 20 | "prepublishOnly": "tsc --declaration --emitDeclarationOnly --allowJs index.js from.js" 21 | }, 22 | "repository": "https://github.com/node-fetch/fetch-blob.git", 23 | "keywords": [ 24 | "blob", 25 | "file", 26 | "node-fetch" 27 | ], 28 | "engines": { 29 | "node": "^12.20 || >= 14.13" 30 | }, 31 | "author": "Jimmy Wärting (https://jimmy.warting.se)", 32 | "license": "MIT", 33 | "bugs": { 34 | "url": "https://github.com/node-fetch/fetch-blob/issues" 35 | }, 36 | "homepage": "https://github.com/node-fetch/fetch-blob#readme", 37 | "devDependencies": { 38 | "@types/node": "^17.0.9", 39 | "c8": "^7.11.0", 40 | "typescript": "^4.5.4" 41 | }, 42 | "funding": [ 43 | { 44 | "type": "github", 45 | "url": "https://github.com/sponsors/jimmywarting" 46 | }, 47 | { 48 | "type": "paypal", 49 | "url": "https://paypal.me/jimmywarting" 50 | } 51 | ], 52 | "dependencies": { 53 | "node-domexception": "^1.0.0", 54 | "web-streams-polyfill": "^3.0.3" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /1371-find-the-longest-substring-containing-vowels-in-even-counts/README.md: -------------------------------------------------------------------------------- 1 |

Find the Longest Substring Containing Vowels in Even Counts

Difficulty: Medium

Given the string s, return the size of the longest substring containing each vowel an even number of times. That is, 'a', 'e', 'i', 'o', and 'u' must appear an even number of times.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
 7 | Input: s = "eleetminicoworoep"
 8 | Output: 13
 9 | Explanation: The longest substring is "leetminicowor" which contains two each of the vowels: e, i and o and zero of the vowels: a and u.
10 | 
11 | 12 |

Example 2:

13 | 14 |
15 | Input: s = "leetcodeisgreat"
16 | Output: 5
17 | Explanation: The longest substring is "leetc" which contains two e's.
18 | 
19 | 20 |

Example 3:

21 | 22 |
23 | Input: s = "bcbcbc"
24 | Output: 6
25 | Explanation: In this case, the given string "bcbcbc" is the longest because all vowels: a, e, i, o and u appear zero times.
26 | 
27 | 28 |

 

29 |

Constraints:

30 | 31 |
    32 |
  • 1 <= s.length <= 5 x 10^5
  • 33 |
  • s contains only lowercase English letters.
  • 34 |
35 | -------------------------------------------------------------------------------- /1310-xor-queries-of-a-subarray/README.md: -------------------------------------------------------------------------------- 1 |

XOR Queries of a Subarray

Difficulty: Medium

You are given an array arr of positive integers. You are also given the array queries where queries[i] = [lefti, righti].

2 | 3 |

For each query i compute the XOR of elements from lefti to righti (that is, arr[lefti] XOR arr[lefti + 1] XOR ... XOR arr[righti] ).

4 | 5 |

Return an array answer where answer[i] is the answer to the ith query.

6 | 7 |

 

8 |

Example 1:

9 | 10 |
11 | Input: arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]]
12 | Output: [2,7,14,8] 
13 | Explanation: 
14 | The binary representation of the elements in the array are:
15 | 1 = 0001 
16 | 3 = 0011 
17 | 4 = 0100 
18 | 8 = 1000 
19 | The XOR values for queries are:
20 | [0,1] = 1 xor 3 = 2 
21 | [1,2] = 3 xor 4 = 7 
22 | [0,3] = 1 xor 3 xor 4 xor 8 = 14 
23 | [3,3] = 8
24 | 
25 | 26 |

Example 2:

27 | 28 |
29 | Input: arr = [4,8,2,10], queries = [[2,3],[1,3],[0,0],[0,3]]
30 | Output: [8,0,4,4]
31 | 
32 | 33 |

 

34 |

Constraints:

35 | 36 |
    37 |
  • 1 <= arr.length, queries.length <= 3 * 104
  • 38 |
  • 1 <= arr[i] <= 109
  • 39 |
  • queries[i].length == 2
  • 40 |
  • 0 <= lefti <= righti < arr.length
  • 41 |
42 | -------------------------------------------------------------------------------- /2419-longest-subarray-with-maximum-bitwise-and/README.md: -------------------------------------------------------------------------------- 1 |

Longest Subarray With Maximum Bitwise AND

Difficulty: Medium

You are given an integer array nums of size n.

2 | 3 |

Consider a non-empty subarray from nums that has the maximum possible bitwise AND.

4 | 5 |
    6 |
  • In other words, let k be the maximum value of the bitwise AND of any subarray of nums. Then, only subarrays with a bitwise AND equal to k should be considered.
  • 7 |
8 | 9 |

Return the length of the longest such subarray.

10 | 11 |

The bitwise AND of an array is the bitwise AND of all the numbers in it.

12 | 13 |

A subarray is a contiguous sequence of elements within an array.

14 | 15 |

 

16 |

Example 1:

17 | 18 |
19 | Input: nums = [1,2,3,3,2,2]
20 | Output: 2
21 | Explanation:
22 | The maximum possible bitwise AND of a subarray is 3.
23 | The longest subarray with that value is [3,3], so we return 2.
24 | 
25 | 26 |

Example 2:

27 | 28 |
29 | Input: nums = [1,2,3,4]
30 | Output: 1
31 | Explanation:
32 | The maximum possible bitwise AND of a subarray is 4.
33 | The longest subarray with that value is [4], so we return 1.
34 | 
35 | 36 |

 

37 |

Constraints:

38 | 39 |
    40 |
  • 1 <= nums.length <= 105
  • 41 |
  • 1 <= nums[i] <= 106
  • 42 |
43 | -------------------------------------------------------------------------------- /2326-spiral-matrix-iv/README.md: -------------------------------------------------------------------------------- 1 |

Spiral Matrix IV

Difficulty: Medium

You are given two integers m and n, which represent the dimensions of a matrix.

2 | 3 |

You are also given the head of a linked list of integers.

4 | 5 |

Generate an m x n matrix that contains the integers in the linked list presented in spiral order (clockwise), starting from the top-left of the matrix. If there are remaining empty spaces, fill them with -1.

6 | 7 |

Return the generated matrix.

8 | 9 |

 

10 |

Example 1:

11 | 12 |
13 | Input: m = 3, n = 5, head = [3,0,2,6,8,1,7,9,4,2,5,5,0]
14 | Output: [[3,0,2,6,8],[5,0,-1,-1,1],[5,2,4,9,7]]
15 | Explanation: The diagram above shows how the values are printed in the matrix.
16 | Note that the remaining spaces in the matrix are filled with -1.
17 | 
18 | 19 |

Example 2:

20 | 21 |
22 | Input: m = 1, n = 4, head = [0,1,2]
23 | Output: [[0,1,2,-1]]
24 | Explanation: The diagram above shows how the values are printed from left to right in the matrix.
25 | The last space in the matrix is set to -1.
26 | 27 |

 

28 |

Constraints:

29 | 30 |
    31 |
  • 1 <= m, n <= 105
  • 32 |
  • 1 <= m * n <= 105
  • 33 |
  • The number of nodes in the list is in the range [1, m * n].
  • 34 |
  • 0 <= Node.val <= 1000
  • 35 |
36 | -------------------------------------------------------------------------------- /scripts/node_modules/data-uri-to-buffer/dist/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Returns a `Buffer` instance from the given data URI `uri`. 3 | * 4 | * @param {String} uri Data URI to turn into a Buffer instance 5 | * @returns {Buffer} Buffer instance from Data URI 6 | * @api public 7 | */ 8 | export function dataUriToBuffer(uri) { 9 | if (!/^data:/i.test(uri)) { 10 | throw new TypeError('`uri` does not appear to be a Data URI (must begin with "data:")'); 11 | } 12 | // strip newlines 13 | uri = uri.replace(/\r?\n/g, ''); 14 | // split the URI up into the "metadata" and the "data" portions 15 | const firstComma = uri.indexOf(','); 16 | if (firstComma === -1 || firstComma <= 4) { 17 | throw new TypeError('malformed data: URI'); 18 | } 19 | // remove the "data:" scheme and parse the metadata 20 | const meta = uri.substring(5, firstComma).split(';'); 21 | let charset = ''; 22 | let base64 = false; 23 | const type = meta[0] || 'text/plain'; 24 | let typeFull = type; 25 | for (let i = 1; i < meta.length; i++) { 26 | if (meta[i] === 'base64') { 27 | base64 = true; 28 | } 29 | else if (meta[i]) { 30 | typeFull += `;${meta[i]}`; 31 | if (meta[i].indexOf('charset=') === 0) { 32 | charset = meta[i].substring(8); 33 | } 34 | } 35 | } 36 | // defaults to US-ASCII only if type is not provided 37 | if (!meta[0] && !charset.length) { 38 | typeFull += ';charset=US-ASCII'; 39 | charset = 'US-ASCII'; 40 | } 41 | // get the encoded data portion and decode URI-encoded chars 42 | const encoding = base64 ? 'base64' : 'ascii'; 43 | const data = unescape(uri.substring(firstComma + 1)); 44 | const buffer = Buffer.from(data, encoding); 45 | // set `.type` and `.typeFull` properties to MIME type 46 | buffer.type = type; 47 | buffer.typeFull = typeFull; 48 | // set the `.charset` property 49 | buffer.charset = charset; 50 | return buffer; 51 | } 52 | export default dataUriToBuffer; 53 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /884-uncommon-words-from-two-sentences/README.md: -------------------------------------------------------------------------------- 1 |

Uncommon Words from Two Sentences

Difficulty: Easy

A sentence is a string of single-space separated words where each word consists only of lowercase letters.

2 | 3 |

A word is uncommon if it appears exactly once in one of the sentences, and does not appear in the other sentence.

4 | 5 |

Given two sentences s1 and s2, return a list of all the uncommon words. You may return the answer in any order.

6 | 7 |

 

8 |

Example 1:

9 | 10 |
11 |

Input: s1 = "this apple is sweet", s2 = "this apple is sour"

12 | 13 |

Output: ["sweet","sour"]

14 | 15 |

Explanation:

16 | 17 |

The word "sweet" appears only in s1, while the word "sour" appears only in s2.

18 |
19 | 20 |

Example 2:

21 | 22 |
23 |

Input: s1 = "apple apple", s2 = "banana"

24 | 25 |

Output: ["banana"]

26 |
27 | 28 |

 

29 |

Constraints:

30 | 31 |
    32 |
  • 1 <= s1.length, s2.length <= 200
  • 33 |
  • s1 and s2 consist of lowercase English letters and spaces.
  • 34 |
  • s1 and s2 do not have leading or trailing spaces.
  • 35 |
  • All the words in s1 and s2 are separated by a single space.
  • 36 |
37 | -------------------------------------------------------------------------------- /scripts/node_modules/data-uri-to-buffer/src/index.ts: -------------------------------------------------------------------------------- 1 | export interface MimeBuffer extends Buffer { 2 | type: string; 3 | typeFull: string; 4 | charset: string; 5 | } 6 | 7 | /** 8 | * Returns a `Buffer` instance from the given data URI `uri`. 9 | * 10 | * @param {String} uri Data URI to turn into a Buffer instance 11 | * @returns {Buffer} Buffer instance from Data URI 12 | * @api public 13 | */ 14 | export function dataUriToBuffer(uri: string): MimeBuffer { 15 | if (!/^data:/i.test(uri)) { 16 | throw new TypeError( 17 | '`uri` does not appear to be a Data URI (must begin with "data:")' 18 | ); 19 | } 20 | 21 | // strip newlines 22 | uri = uri.replace(/\r?\n/g, ''); 23 | 24 | // split the URI up into the "metadata" and the "data" portions 25 | const firstComma = uri.indexOf(','); 26 | if (firstComma === -1 || firstComma <= 4) { 27 | throw new TypeError('malformed data: URI'); 28 | } 29 | 30 | // remove the "data:" scheme and parse the metadata 31 | const meta = uri.substring(5, firstComma).split(';'); 32 | 33 | let charset = ''; 34 | let base64 = false; 35 | const type = meta[0] || 'text/plain'; 36 | let typeFull = type; 37 | for (let i = 1; i < meta.length; i++) { 38 | if (meta[i] === 'base64') { 39 | base64 = true; 40 | } else if(meta[i]) { 41 | typeFull += `;${ meta[i]}`; 42 | if (meta[i].indexOf('charset=') === 0) { 43 | charset = meta[i].substring(8); 44 | } 45 | } 46 | } 47 | // defaults to US-ASCII only if type is not provided 48 | if (!meta[0] && !charset.length) { 49 | typeFull += ';charset=US-ASCII'; 50 | charset = 'US-ASCII'; 51 | } 52 | 53 | // get the encoded data portion and decode URI-encoded chars 54 | const encoding = base64 ? 'base64' : 'ascii'; 55 | const data = unescape(uri.substring(firstComma + 1)); 56 | const buffer = Buffer.from(data, encoding) as MimeBuffer; 57 | 58 | // set `.type` and `.typeFull` properties to MIME type 59 | buffer.type = type; 60 | buffer.typeFull = typeFull; 61 | 62 | // set the `.charset` property 63 | buffer.charset = charset; 64 | 65 | return buffer; 66 | } 67 | 68 | export default dataUriToBuffer; 69 | -------------------------------------------------------------------------------- /725-split-linked-list-in-parts/README.md: -------------------------------------------------------------------------------- 1 |

Split Linked List in Parts

Difficulty: Medium

Given the head of a singly linked list and an integer k, split the linked list into k consecutive linked list parts.

2 | 3 |

The length of each part should be as equal as possible: no two parts should have a size differing by more than one. This may lead to some parts being null.

4 | 5 |

The parts should be in the order of occurrence in the input list, and parts occurring earlier should always have a size greater than or equal to parts occurring later.

6 | 7 |

Return an array of the k parts.

8 | 9 |

 

10 |

Example 1:

11 | 12 |
13 | Input: head = [1,2,3], k = 5
14 | Output: [[1],[2],[3],[],[]]
15 | Explanation:
16 | The first element output[0] has output[0].val = 1, output[0].next = null.
17 | The last element output[4] is null, but its string representation as a ListNode is [].
18 | 
19 | 20 |

Example 2:

21 | 22 |
23 | Input: head = [1,2,3,4,5,6,7,8,9,10], k = 3
24 | Output: [[1,2,3,4],[5,6,7],[8,9,10]]
25 | Explanation:
26 | The input has been split into consecutive parts with size difference at most 1, and earlier parts are a larger size than the later parts.
27 | 
28 | 29 |

 

30 |

Constraints:

31 | 32 |
    33 |
  • The number of nodes in the list is in the range [0, 1000].
  • 34 |
  • 0 <= Node.val <= 1000
  • 35 |
  • 1 <= k <= 50
  • 36 |
37 | -------------------------------------------------------------------------------- /2938-separate-black-and-white-balls/README.md: -------------------------------------------------------------------------------- 1 |

Separate Black and White Balls

Difficulty: Medium

There are n balls on a table, each ball has a color black or white.

2 | 3 |

You are given a 0-indexed binary string s of length n, where 1 and 0 represent black and white balls, respectively.

4 | 5 |

In each step, you can choose two adjacent balls and swap them.

6 | 7 |

Return the minimum number of steps to group all the black balls to the right and all the white balls to the left.

8 | 9 |

 

10 |

Example 1:

11 | 12 |
13 | Input: s = "101"
14 | Output: 1
15 | Explanation: We can group all the black balls to the right in the following way:
16 | - Swap s[0] and s[1], s = "011".
17 | Initially, 1s are not grouped together, requiring at least 1 step to group them to the right.
18 | 19 |

Example 2:

20 | 21 |
22 | Input: s = "100"
23 | Output: 2
24 | Explanation: We can group all the black balls to the right in the following way:
25 | - Swap s[0] and s[1], s = "010".
26 | - Swap s[1] and s[2], s = "001".
27 | It can be proven that the minimum number of steps needed is 2.
28 | 
29 | 30 |

Example 3:

31 | 32 |
33 | Input: s = "0111"
34 | Output: 0
35 | Explanation: All the black balls are already grouped to the right.
36 | 
37 | 38 |

 

39 |

Constraints:

40 | 41 |
    42 |
  • 1 <= n == s.length <= 105
  • 43 |
  • s[i] is either '0' or '1'.
  • 44 |
45 | -------------------------------------------------------------------------------- /729-my-calendar-i/README.md: -------------------------------------------------------------------------------- 1 |

My Calendar I

Difficulty: Medium

You are implementing a program to use as your calendar. We can add a new event if adding the event will not cause a double booking.

2 | 3 |

A double booking happens when two events have some non-empty intersection (i.e., some moment is common to both events.).

4 | 5 |

The event can be represented as a pair of integers start and end that represents a booking on the half-open interval [start, end), the range of real numbers x such that start <= x < end.

6 | 7 |

Implement the MyCalendar class:

8 | 9 |
    10 |
  • MyCalendar() Initializes the calendar object.
  • 11 |
  • boolean book(int start, int end) Returns true if the event can be added to the calendar successfully without causing a double booking. Otherwise, return false and do not add the event to the calendar.
  • 12 |
13 | 14 |

 

15 |

Example 1:

16 | 17 |
18 | Input
19 | ["MyCalendar", "book", "book", "book"]
20 | [[], [10, 20], [15, 25], [20, 30]]
21 | Output
22 | [null, true, false, true]
23 | 
24 | Explanation
25 | MyCalendar myCalendar = new MyCalendar();
26 | myCalendar.book(10, 20); // return True
27 | myCalendar.book(15, 25); // return False, It can not be booked because time 15 is already booked by another event.
28 | myCalendar.book(20, 30); // return True, The event can be booked, as the first event takes every time less than 20, but not including 20.
29 | 30 |

 

31 |

Constraints:

32 | 33 |
    34 |
  • 0 <= start < end <= 109
  • 35 |
  • At most 1000 calls will be made to book.
  • 36 |
37 | -------------------------------------------------------------------------------- /2707-extra-characters-in-a-string/README.md: -------------------------------------------------------------------------------- 1 |

Extra Characters in a String

Difficulty: Medium

You are given a 0-indexed string s and a dictionary of words dictionary. You have to break s into one or more non-overlapping substrings such that each substring is present in dictionary. There may be some extra characters in s which are not present in any of the substrings.

2 | 3 |

Return the minimum number of extra characters left over if you break up s optimally.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
 9 | Input: s = "leetscode", dictionary = ["leet","code","leetcode"]
10 | Output: 1
11 | Explanation: We can break s in two substrings: "leet" from index 0 to 3 and "code" from index 5 to 8. There is only 1 unused character (at index 4), so we return 1.
12 | 
13 | 
14 | 15 |

Example 2:

16 | 17 |
18 | Input: s = "sayhelloworld", dictionary = ["hello","world"]
19 | Output: 3
20 | Explanation: We can break s in two substrings: "hello" from index 3 to 7 and "world" from index 8 to 12. The characters at indices 0, 1, 2 are not used in any substring and thus are considered as extra characters. Hence, we return 3.
21 | 
22 | 23 |

 

24 |

Constraints:

25 | 26 |
    27 |
  • 1 <= s.length <= 50
  • 28 |
  • 1 <= dictionary.length <= 50
  • 29 |
  • 1 <= dictionary[i].length <= 50
  • 30 |
  • dictionary[i] and s consists of only lowercase English letters
  • 31 |
  • dictionary contains distinct words
  • 32 |
33 | -------------------------------------------------------------------------------- /scripts/node_modules/node-domexception/README.md: -------------------------------------------------------------------------------- 1 | # DOMException 2 | An implementation of the DOMException class from NodeJS 3 | 4 | NodeJS has DOMException built in, but it's not globally available, and you can't require/import it from somewhere. 5 | 6 | This package exposes the [`DOMException`](https://developer.mozilla.org/en-US/docs/Web/API/DOMException) class that comes from NodeJS itself. (including all of the legacy codes) 7 | 8 | (plz don't depend on this package in any other environment other than node >=10.5) 9 | 10 | ```js 11 | import DOMException from 'node-domexception' 12 | import { MessageChannel } from 'worker_threads' 13 | 14 | async function hello() { 15 | const port = new MessageChannel().port1 16 | const ab = new ArrayBuffer() 17 | port.postMessage(ab, [ab, ab]) 18 | } 19 | 20 | hello().catch(err => { 21 | console.assert(err.name === 'DataCloneError') 22 | console.assert(err.code === 25) 23 | console.assert(err instanceof DOMException) 24 | }) 25 | 26 | const e1 = new DOMException('Something went wrong', 'BadThingsError') 27 | console.assert(e1.name === 'BadThingsError') 28 | console.assert(e1.code === 0) 29 | 30 | const e2 = new DOMException('Another exciting error message', 'NoModificationAllowedError') 31 | console.assert(e2.name === 'NoModificationAllowedError') 32 | console.assert(e2.code === 7) 33 | 34 | console.assert(DOMException.INUSE_ATTRIBUTE_ERR === 10) 35 | ``` 36 | 37 | # Background 38 | 39 | The only possible way is to use some web-ish tools that have been introduced into NodeJS that throws a DOMException and catch the constructor. This is exactly what this package dose for you and exposes it.
40 | This way you will have the same class that NodeJS has and you can check if the error is a instance of DOMException.
41 | The instanceof check would not have worked with a custom class such as the DOMException provided by domenic which also is much larger in size since it has to re-construct the hole class from the ground up. 42 | 43 | The DOMException is used in many places such as the Fetch API, File & Blobs, PostMessaging and more.
44 | Why they decided to call it **DOM**, I don't know 45 | 46 | Please consider sponsoring if you find this helpful 47 | -------------------------------------------------------------------------------- /1367-linked-list-in-binary-tree/README.md: -------------------------------------------------------------------------------- 1 |

Linked List in Binary Tree

Difficulty: Medium

Given a binary tree root and a linked list with head as the first node. 

2 | 3 |

Return True if all the elements in the linked list starting from the head correspond to some downward path connected in the binary tree otherwise return False.

4 | 5 |

In this context downward path means a path that starts at some node and goes downwards.

6 | 7 |

 

8 |

Example 1:

9 | 10 |

11 | 12 |
13 | Input: head = [4,2,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]
14 | Output: true
15 | Explanation: Nodes in blue form a subpath in the binary Tree.  
16 | 
17 | 18 |

Example 2:

19 | 20 |

21 | 22 |
23 | Input: head = [1,4,2,6], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]
24 | Output: true
25 | 
26 | 27 |

Example 3:

28 | 29 |
30 | Input: head = [1,4,2,6,8], root = [1,4,4,null,2,2,null,1,null,6,8,null,null,null,null,1,3]
31 | Output: false
32 | Explanation: There is no path in the binary tree that contains all the elements of the linked list from head.
33 | 
34 | 35 |

 

36 |

Constraints:

37 | 38 |
    39 |
  • The number of nodes in the tree will be in the range [1, 2500].
  • 40 |
  • The number of nodes in the list will be in the range [1, 100].
  • 41 |
  • 1 <= Node.val <= 100 for each node in the linked list and binary tree.
  • 42 |
43 | -------------------------------------------------------------------------------- /1684-count-the-number-of-consistent-strings/README.md: -------------------------------------------------------------------------------- 1 |

Count the Number of Consistent Strings

Difficulty: Easy

You are given a string allowed consisting of distinct characters and an array of strings words. A string is consistent if all characters in the string appear in the string allowed.

2 | 3 |

Return the number of consistent strings in the array words.

4 | 5 |

 

6 |

Example 1:

7 | 8 |
 9 | Input: allowed = "ab", words = ["ad","bd","aaab","baa","badab"]
10 | Output: 2
11 | Explanation: Strings "aaab" and "baa" are consistent since they only contain characters 'a' and 'b'.
12 | 
13 | 14 |

Example 2:

15 | 16 |
17 | Input: allowed = "abc", words = ["a","b","c","ab","ac","bc","abc"]
18 | Output: 7
19 | Explanation: All strings are consistent.
20 | 
21 | 22 |

Example 3:

23 | 24 |
25 | Input: allowed = "cad", words = ["cc","acd","b","ba","bac","bad","ac","d"]
26 | Output: 4
27 | Explanation: Strings "cc", "acd", "ac", and "d" are consistent.
28 | 
29 | 30 |

 

31 |

Constraints:

32 | 33 |
    34 |
  • 1 <= words.length <= 104
  • 35 |
  • 1 <= allowed.length <= 26
  • 36 |
  • 1 <= words[i].length <= 10
  • 37 |
  • The characters in allowed are distinct.
  • 38 |
  • words[i] and allowed contain only lowercase English letters.
  • 39 |
40 | -------------------------------------------------------------------------------- /641-design-circular-deque/design-circular-deque.java: -------------------------------------------------------------------------------- 1 | class MyCircularDeque { 2 | private int[] v; 3 | private int front, back, size, capacity; 4 | 5 | public MyCircularDeque(int k) { 6 | v = new int[k]; 7 | Arrays.fill(v, -1); 8 | front = 0; 9 | back = 0; 10 | size = 0; 11 | capacity = k; 12 | } 13 | 14 | public boolean insertFront(int value) { 15 | if (isFull()) { 16 | return false; 17 | } 18 | 19 | if (front == 0) { 20 | front = capacity - 1; 21 | } else { 22 | front--; 23 | } 24 | 25 | v[front] = value; 26 | size++; 27 | return true; 28 | } 29 | 30 | public boolean insertLast(int value) { 31 | if (isFull()) { 32 | return false; 33 | } 34 | 35 | v[back] = value; 36 | 37 | if (back == capacity - 1) { 38 | back = 0; 39 | } else { 40 | back++; 41 | } 42 | 43 | size++; 44 | return true; 45 | } 46 | 47 | public boolean deleteFront() { 48 | if (isEmpty()) { 49 | return false; 50 | } 51 | 52 | v[front] = -1; 53 | 54 | if (front == capacity - 1) { 55 | front = 0; 56 | } else { 57 | front++; 58 | } 59 | 60 | size--; 61 | return true; 62 | } 63 | 64 | public boolean deleteLast() { 65 | if (isEmpty()) { 66 | return false; 67 | } 68 | 69 | if (back == 0) { 70 | back = capacity - 1; 71 | } else { 72 | back--; 73 | } 74 | v[back] = -1; 75 | 76 | size--; 77 | return true; 78 | } 79 | 80 | public int getFront() { 81 | if (isEmpty()) { 82 | return -1; 83 | } 84 | return v[front]; 85 | } 86 | 87 | public int getRear() { 88 | if (isEmpty()) { 89 | return -1; 90 | } 91 | if (back == 0) { 92 | return v[capacity - 1]; 93 | } else { 94 | return v[back - 1]; 95 | } 96 | } 97 | 98 | public boolean isEmpty() { 99 | return size == 0; 100 | } 101 | 102 | public boolean isFull() { 103 | return size == capacity; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /2807-insert-greatest-common-divisors-in-linked-list/README.md: -------------------------------------------------------------------------------- 1 |

Insert Greatest Common Divisors in Linked List

Difficulty: Medium

Given the head of a linked list head, in which each node contains an integer value.

2 | 3 |

Between every pair of adjacent nodes, insert a new node with a value equal to the greatest common divisor of them.

4 | 5 |

Return the linked list after insertion.

6 | 7 |

The greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.

8 | 9 |

 

10 |

Example 1:

11 | 12 |
13 | Input: head = [18,6,10,3]
14 | Output: [18,6,6,2,10,1,3]
15 | Explanation: The 1st diagram denotes the initial linked list and the 2nd diagram denotes the linked list after inserting the new nodes (nodes in blue are the inserted nodes).
16 | - We insert the greatest common divisor of 18 and 6 = 6 between the 1st and the 2nd nodes.
17 | - We insert the greatest common divisor of 6 and 10 = 2 between the 2nd and the 3rd nodes.
18 | - We insert the greatest common divisor of 10 and 3 = 1 between the 3rd and the 4th nodes.
19 | There are no more adjacent nodes, so we return the linked list.
20 | 
21 | 22 |

Example 2:

23 | 24 |
25 | Input: head = [7]
26 | Output: [7]
27 | Explanation: The 1st diagram denotes the initial linked list and the 2nd diagram denotes the linked list after inserting the new nodes.
28 | There are no pairs of adjacent nodes, so we return the initial linked list.
29 | 
30 | 31 |

 

32 |

Constraints:

33 | 34 |
    35 |
  • The number of nodes in the list is in the range [1, 5000].
  • 36 |
  • 1 <= Node.val <= 1000
  • 37 |
38 | -------------------------------------------------------------------------------- /2220-minimum-bit-flips-to-convert-number/README.md: -------------------------------------------------------------------------------- 1 |

Minimum Bit Flips to Convert Number

Difficulty: Easy

A bit flip of a number x is choosing a bit in the binary representation of x and flipping it from either 0 to 1 or 1 to 0.

2 | 3 |
    4 |
  • For example, for x = 7, the binary representation is 111 and we may choose any bit (including any leading zeros not shown) and flip it. We can flip the first bit from the right to get 110, flip the second bit from the right to get 101, flip the fifth bit from the right (a leading zero) to get 10111, etc.
  • 5 |
6 | 7 |

Given two integers start and goal, return the minimum number of bit flips to convert start to goal.

8 | 9 |

 

10 |

Example 1:

11 | 12 |
13 | Input: start = 10, goal = 7
14 | Output: 3
15 | Explanation: The binary representation of 10 and 7 are 1010 and 0111 respectively. We can convert 10 to 7 in 3 steps:
16 | - Flip the first bit from the right: 1010 -> 1011.
17 | - Flip the third bit from the right: 1011 -> 1111.
18 | - Flip the fourth bit from the right: 1111 -> 0111.
19 | It can be shown we cannot convert 10 to 7 in less than 3 steps. Hence, we return 3.
20 | 21 |

Example 2:

22 | 23 |
24 | Input: start = 3, goal = 4
25 | Output: 3
26 | Explanation: The binary representation of 3 and 4 are 011 and 100 respectively. We can convert 3 to 4 in 3 steps:
27 | - Flip the first bit from the right: 011 -> 010.
28 | - Flip the second bit from the right: 010 -> 000.
29 | - Flip the third bit from the right: 000 -> 100.
30 | It can be shown we cannot convert 3 to 4 in less than 3 steps. Hence, we return 3.
31 | 
32 | 33 |

 

34 |

Constraints:

35 | 36 |
    37 |
  • 0 <= start, goal <= 109
  • 38 |
39 | -------------------------------------------------------------------------------- /scripts/node_modules/formdata-polyfill/esm.min.js: -------------------------------------------------------------------------------- 1 | /*! formdata-polyfill. MIT License. Jimmy Wärting */ 2 | 3 | import C from 'fetch-blob' 4 | import F from 'fetch-blob/file.js' 5 | 6 | var {toStringTag:t,iterator:i,hasInstance:h}=Symbol, 7 | r=Math.random, 8 | m='append,set,get,getAll,delete,keys,values,entries,forEach,constructor'.split(','), 9 | f=(a,b,c)=>(a+='',/^(Blob|File)$/.test(b && b[t])?[(c=c!==void 0?c+'':b[t]=='File'?b.name:'blob',a),b.name!==c||b[t]=='blob'?new F([b],c,b):b]:[a,b+'']), 10 | e=(c,f)=>(f?c:c.replace(/\r?\n|\r/g,'\r\n')).replace(/\n/g,'%0A').replace(/\r/g,'%0D').replace(/"/g,'%22'), 11 | x=(n, a, e)=>{if(a.lengthtypeof o[m]!='function')} 22 | append(...a){x('append',arguments,2);this.#d.push(f(...a))} 23 | delete(a){x('delete',arguments,1);a+='';this.#d=this.#d.filter(([b])=>b!==a)} 24 | get(a){x('get',arguments,1);a+='';for(var b=this.#d,l=b.length,c=0;cc[0]===a&&b.push(c[1]));return b} 26 | has(a){x('has',arguments,1);a+='';return this.#d.some(b=>b[0]===a)} 27 | forEach(a,b){x('forEach',arguments,1);for(var [c,d]of this)a.call(b,d,c,this)} 28 | set(...a){x('set',arguments,2);var b=[],c=!0;a=f(...a);this.#d.forEach(d=>{d[0]===a[0]?c&&(c=!b.push(a)):b.push(d)});c&&b.push(a);this.#d=b} 29 | *entries(){yield*this.#d} 30 | *keys(){for(var[a]of this)yield a} 31 | *values(){for(var[,a]of this)yield a}} 32 | 33 | /** @param {FormData} F */ 34 | export function formDataToBlob (F,B=C){ 35 | var b=`${r()}${r()}`.replace(/\./g, '').slice(-28).padStart(32, '-'),c=[],p=`--${b}\r\nContent-Disposition: form-data; name="` 36 | F.forEach((v,n)=>typeof v=='string' 37 | ?c.push(p+e(n)+`"\r\n\r\n${v.replace(/\r(?!\n)|(?Find the Length of the Longest Common Prefix Difficulty: Medium

You are given two arrays with positive integers arr1 and arr2.

2 | 3 |

A prefix of a positive integer is an integer formed by one or more of its digits, starting from its leftmost digit. For example, 123 is a prefix of the integer 12345, while 234 is not.

4 | 5 |

A common prefix of two integers a and b is an integer c, such that c is a prefix of both a and b. For example, 5655359 and 56554 have a common prefix 565 while 1223 and 43456 do not have a common prefix.

6 | 7 |

You need to find the length of the longest common prefix between all pairs of integers (x, y) such that x belongs to arr1 and y belongs to arr2.

8 | 9 |

Return the length of the longest common prefix among all pairs. If no common prefix exists among them, return 0.

10 | 11 |

 

12 |

Example 1:

13 | 14 |
15 | Input: arr1 = [1,10,100], arr2 = [1000]
16 | Output: 3
17 | Explanation: There are 3 pairs (arr1[i], arr2[j]):
18 | - The longest common prefix of (1, 1000) is 1.
19 | - The longest common prefix of (10, 1000) is 10.
20 | - The longest common prefix of (100, 1000) is 100.
21 | The longest common prefix is 100 with a length of 3.
22 | 
23 | 24 |

Example 2:

25 | 26 |
27 | Input: arr1 = [1,2,3], arr2 = [4,4,4]
28 | Output: 0
29 | Explanation: There exists no common prefix for any pair (arr1[i], arr2[j]), hence we return 0.
30 | Note that common prefixes between elements of the same array do not count.
31 | 
32 | 33 |

 

34 |

Constraints:

35 | 36 |
    37 |
  • 1 <= arr1.length, arr2.length <= 5 * 104
  • 38 |
  • 1 <= arr1[i], arr2[i] <= 108
  • 39 |
40 | -------------------------------------------------------------------------------- /2028-find-missing-observations/README.md: -------------------------------------------------------------------------------- 1 |

Find Missing Observations

Difficulty: Medium

You have observations of n + m 6-sided dice rolls with each face numbered from 1 to 6. n of the observations went missing, and you only have the observations of m rolls. Fortunately, you have also calculated the average value of the n + m rolls.

2 | 3 |

You are given an integer array rolls of length m where rolls[i] is the value of the ith observation. You are also given the two integers mean and n.

4 | 5 |

Return an array of length n containing the missing observations such that the average value of the n + m rolls is exactly mean. If there are multiple valid answers, return any of them. If no such array exists, return an empty array.

6 | 7 |

The average value of a set of k numbers is the sum of the numbers divided by k.

8 | 9 |

Note that mean is an integer, so the sum of the n + m rolls should be divisible by n + m.

10 | 11 |

 

12 |

Example 1:

13 | 14 |
15 | Input: rolls = [3,2,4,3], mean = 4, n = 2
16 | Output: [6,6]
17 | Explanation: The mean of all n + m rolls is (3 + 2 + 4 + 3 + 6 + 6) / 6 = 4.
18 | 
19 | 20 |

Example 2:

21 | 22 |
23 | Input: rolls = [1,5,6], mean = 3, n = 4
24 | Output: [2,3,2,2]
25 | Explanation: The mean of all n + m rolls is (1 + 5 + 6 + 2 + 3 + 2 + 2) / 7 = 3.
26 | 
27 | 28 |

Example 3:

29 | 30 |
31 | Input: rolls = [1,2,3,4], mean = 6, n = 4
32 | Output: []
33 | Explanation: It is impossible for the mean to be 6 no matter what the 4 missing rolls are.
34 | 
35 | 36 |

 

37 |

Constraints:

38 | 39 |
    40 |
  • m == rolls.length
  • 41 |
  • 1 <= n, m <= 105
  • 42 |
  • 1 <= rolls[i], mean <= 6
  • 43 |
44 | -------------------------------------------------------------------------------- /scripts/node_modules/node-fetch/src/utils/is.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Is.js 3 | * 4 | * Object type checks. 5 | */ 6 | 7 | const NAME = Symbol.toStringTag; 8 | 9 | /** 10 | * Check if `obj` is a URLSearchParams object 11 | * ref: https://github.com/node-fetch/node-fetch/issues/296#issuecomment-307598143 12 | * @param {*} object - Object to check for 13 | * @return {boolean} 14 | */ 15 | export const isURLSearchParameters = object => { 16 | return ( 17 | typeof object === 'object' && 18 | typeof object.append === 'function' && 19 | typeof object.delete === 'function' && 20 | typeof object.get === 'function' && 21 | typeof object.getAll === 'function' && 22 | typeof object.has === 'function' && 23 | typeof object.set === 'function' && 24 | typeof object.sort === 'function' && 25 | object[NAME] === 'URLSearchParams' 26 | ); 27 | }; 28 | 29 | /** 30 | * Check if `object` is a W3C `Blob` object (which `File` inherits from) 31 | * @param {*} object - Object to check for 32 | * @return {boolean} 33 | */ 34 | export const isBlob = object => { 35 | return ( 36 | object && 37 | typeof object === 'object' && 38 | typeof object.arrayBuffer === 'function' && 39 | typeof object.type === 'string' && 40 | typeof object.stream === 'function' && 41 | typeof object.constructor === 'function' && 42 | /^(Blob|File)$/.test(object[NAME]) 43 | ); 44 | }; 45 | 46 | /** 47 | * Check if `obj` is an instance of AbortSignal. 48 | * @param {*} object - Object to check for 49 | * @return {boolean} 50 | */ 51 | export const isAbortSignal = object => { 52 | return ( 53 | typeof object === 'object' && ( 54 | object[NAME] === 'AbortSignal' || 55 | object[NAME] === 'EventTarget' 56 | ) 57 | ); 58 | }; 59 | 60 | /** 61 | * isDomainOrSubdomain reports whether sub is a subdomain (or exact match) of 62 | * the parent domain. 63 | * 64 | * Both domains must already be in canonical form. 65 | * @param {string|URL} original 66 | * @param {string|URL} destination 67 | */ 68 | export const isDomainOrSubdomain = (destination, original) => { 69 | const orig = new URL(original).hostname; 70 | const dest = new URL(destination).hostname; 71 | 72 | return orig === dest || orig.endsWith(`.${dest}`); 73 | }; 74 | 75 | /** 76 | * isSameProtocol reports whether the two provided URLs use the same protocol. 77 | * 78 | * Both domains must already be in canonical form. 79 | * @param {string|URL} original 80 | * @param {string|URL} destination 81 | */ 82 | export const isSameProtocol = (destination, original) => { 83 | const orig = new URL(original).protocol; 84 | const dest = new URL(destination).protocol; 85 | 86 | return orig === dest; 87 | }; 88 | -------------------------------------------------------------------------------- /731-my-calendar-ii/README.md: -------------------------------------------------------------------------------- 1 |

My Calendar II

Difficulty: Medium

You are implementing a program to use as your calendar. We can add a new event if adding the event will not cause a triple booking.

2 | 3 |

A triple booking happens when three events have some non-empty intersection (i.e., some moment is common to all the three events.).

4 | 5 |

The event can be represented as a pair of integers start and end that represents a booking on the half-open interval [start, end), the range of real numbers x such that start <= x < end.

6 | 7 |

Implement the MyCalendarTwo class:

8 | 9 |
    10 |
  • MyCalendarTwo() Initializes the calendar object.
  • 11 |
  • boolean book(int start, int end) Returns true if the event can be added to the calendar successfully without causing a triple booking. Otherwise, return false and do not add the event to the calendar.
  • 12 |
13 | 14 |

 

15 |

Example 1:

16 | 17 |
18 | Input
19 | ["MyCalendarTwo", "book", "book", "book", "book", "book", "book"]
20 | [[], [10, 20], [50, 60], [10, 40], [5, 15], [5, 10], [25, 55]]
21 | Output
22 | [null, true, true, true, false, true, true]
23 | 
24 | Explanation
25 | MyCalendarTwo myCalendarTwo = new MyCalendarTwo();
26 | myCalendarTwo.book(10, 20); // return True, The event can be booked. 
27 | myCalendarTwo.book(50, 60); // return True, The event can be booked. 
28 | myCalendarTwo.book(10, 40); // return True, The event can be double booked. 
29 | myCalendarTwo.book(5, 15);  // return False, The event cannot be booked, because it would result in a triple booking.
30 | myCalendarTwo.book(5, 10); // return True, The event can be booked, as it does not use time 10 which is already double booked.
31 | myCalendarTwo.book(25, 55); // return True, The event can be booked, as the time in [25, 40) will be double booked with the third event, the time [40, 50) will be single booked, and the time [50, 55) will be double booked with the second event.
32 | 
33 | 34 |

 

35 |

Constraints:

36 | 37 |
    38 |
  • 0 <= start < end <= 109
  • 39 |
  • At most 1000 calls will be made to book.
  • 40 |
41 | -------------------------------------------------------------------------------- /2132-convert-1d-array-into-2d-array/README.md: -------------------------------------------------------------------------------- 1 |

Convert 1D Array Into 2D Array

Difficulty: Easy

You are given a 0-indexed 1-dimensional (1D) integer array original, and two integers, m and n. You are tasked with creating a 2-dimensional (2D) array with m rows and n columns using all the elements from original.

2 | 3 |

The elements from indices 0 to n - 1 (inclusive) of original should form the first row of the constructed 2D array, the elements from indices n to 2 * n - 1 (inclusive) should form the second row of the constructed 2D array, and so on.

4 | 5 |

Return an m x n 2D array constructed according to the above procedure, or an empty 2D array if it is impossible.

6 | 7 |

 

8 |

Example 1:

9 | 10 |
11 | Input: original = [1,2,3,4], m = 2, n = 2
12 | Output: [[1,2],[3,4]]
13 | Explanation: The constructed 2D array should contain 2 rows and 2 columns.
14 | The first group of n=2 elements in original, [1,2], becomes the first row in the constructed 2D array.
15 | The second group of n=2 elements in original, [3,4], becomes the second row in the constructed 2D array.
16 | 
17 | 18 |

Example 2:

19 | 20 |
21 | Input: original = [1,2,3], m = 1, n = 3
22 | Output: [[1,2,3]]
23 | Explanation: The constructed 2D array should contain 1 row and 3 columns.
24 | Put all three elements in original into the first row of the constructed 2D array.
25 | 
26 | 27 |

Example 3:

28 | 29 |
30 | Input: original = [1,2], m = 1, n = 1
31 | Output: []
32 | Explanation: There are 2 elements in original.
33 | It is impossible to fit 2 elements in a 1x1 2D array, so return an empty 2D array.
34 | 
35 | 36 |

 

37 |

Constraints:

38 | 39 |
    40 |
  • 1 <= original.length <= 5 * 104
  • 41 |
  • 1 <= original[i] <= 105
  • 42 |
  • 1 <= m, n <= 4 * 104
  • 43 |
44 | -------------------------------------------------------------------------------- /3217-delete-nodes-from-linked-list-present-in-array/README.md: -------------------------------------------------------------------------------- 1 |

Delete Nodes From Linked List Present in Array

Difficulty: Medium

You are given an array of integers nums and the head of a linked list. Return the head of the modified linked list after removing all nodes from the linked list that have a value that exists in nums.

2 | 3 |

 

4 |

Example 1:

5 | 6 |
7 |

Input: nums = [1,2,3], head = [1,2,3,4,5]

8 | 9 |

Output: [4,5]

10 | 11 |

Explanation:

12 | 13 |

14 | 15 |

Remove the nodes with values 1, 2, and 3.

16 |
17 | 18 |

Example 2:

19 | 20 |
21 |

Input: nums = [1], head = [1,2,1,2,1,2]

22 | 23 |

Output: [2,2,2]

24 | 25 |

Explanation:

26 | 27 |

28 | 29 |

Remove the nodes with value 1.

30 |
31 | 32 |

Example 3:

33 | 34 |
35 |

Input: nums = [5], head = [1,2,3,4]

36 | 37 |

Output: [1,2,3,4]

38 | 39 |

Explanation:

40 | 41 |

42 | 43 |

No node has value 5.

44 |
45 | 46 |

 

47 |

Constraints:

48 | 49 |
    50 |
  • 1 <= nums.length <= 105
  • 51 |
  • 1 <= nums[i] <= 105
  • 52 |
  • All elements in nums are unique.
  • 53 |
  • The number of nodes in the given list is in the range [1, 105].
  • 54 |
  • 1 <= Node.val <= 105
  • 55 |
  • The input is generated such that there is at least one node in the linked list that has a value not present in nums.
  • 56 |
57 | -------------------------------------------------------------------------------- /1945-sum-of-digits-of-string-after-convert/README.md: -------------------------------------------------------------------------------- 1 |

Sum of Digits of String After Convert

Difficulty: Easy

You are given a string s consisting of lowercase English letters, and an integer k.

2 | 3 |

First, convert s into an integer by replacing each letter with its position in the alphabet (i.e., replace 'a' with 1, 'b' with 2, ..., 'z' with 26). Then, transform the integer by replacing it with the sum of its digits. Repeat the transform operation k times in total.

4 | 5 |

For example, if s = "zbax" and k = 2, then the resulting integer would be 8 by the following operations:

6 | 7 |
    8 |
  • Convert: "zbax" ➝ "(26)(2)(1)(24)" ➝ "262124" ➝ 262124
  • 9 |
  • Transform #1: 262124 ➝ 2 + 6 + 2 + 1 + 2 + 4 ➝ 17
  • 10 |
  • Transform #2: 17 ➝ 1 + 7 ➝ 8
  • 11 |
12 | 13 |

Return the resulting integer after performing the operations described above.

14 | 15 |

 

16 |

Example 1:

17 | 18 |
19 | Input: s = "iiii", k = 1
20 | Output: 36
21 | Explanation: The operations are as follows:
22 | - Convert: "iiii" ➝ "(9)(9)(9)(9)" ➝ "9999" ➝ 9999
23 | - Transform #1: 9999 ➝ 9 + 9 + 9 + 9 ➝ 36
24 | Thus the resulting integer is 36.
25 | 
26 | 27 |

Example 2:

28 | 29 |
30 | Input: s = "leetcode", k = 2
31 | Output: 6
32 | Explanation: The operations are as follows:
33 | - Convert: "leetcode" ➝ "(12)(5)(5)(20)(3)(15)(4)(5)" ➝ "12552031545" ➝ 12552031545
34 | - Transform #1: 12552031545 ➝ 1 + 2 + 5 + 5 + 2 + 0 + 3 + 1 + 5 + 4 + 5 ➝ 33
35 | - Transform #2: 33 ➝ 3 + 3 ➝ 6
36 | Thus the resulting integer is 6.
37 | 
38 | 39 |

Example 3:

40 | 41 |
42 | Input: s = "zbax", k = 2
43 | Output: 8
44 | 
45 | 46 |

 

47 |

Constraints:

48 | 49 |
    50 |
  • 1 <= s.length <= 100
  • 51 |
  • 1 <= k <= 10
  • 52 |
  • s consists of lowercase English letters.
  • 53 |
54 | -------------------------------------------------------------------------------- /432-all-oone-data-structure/README.md: -------------------------------------------------------------------------------- 1 |

All O`one Data Structure

Difficulty: Hard

Design a data structure to store the strings' count with the ability to return the strings with minimum and maximum counts.

2 | 3 |

Implement the AllOne class:

4 | 5 |
    6 |
  • AllOne() Initializes the object of the data structure.
  • 7 |
  • inc(String key) Increments the count of the string key by 1. If key does not exist in the data structure, insert it with count 1.
  • 8 |
  • dec(String key) Decrements the count of the string key by 1. If the count of key is 0 after the decrement, remove it from the data structure. It is guaranteed that key exists in the data structure before the decrement.
  • 9 |
  • getMaxKey() Returns one of the keys with the maximal count. If no element exists, return an empty string "".
  • 10 |
  • getMinKey() Returns one of the keys with the minimum count. If no element exists, return an empty string "".
  • 11 |
12 | 13 |

Note that each function must run in O(1) average time complexity.

14 | 15 |

 

16 |

Example 1:

17 | 18 |
19 | Input
20 | ["AllOne", "inc", "inc", "getMaxKey", "getMinKey", "inc", "getMaxKey", "getMinKey"]
21 | [[], ["hello"], ["hello"], [], [], ["leet"], [], []]
22 | Output
23 | [null, null, null, "hello", "hello", null, "hello", "leet"]
24 | 
25 | Explanation
26 | AllOne allOne = new AllOne();
27 | allOne.inc("hello");
28 | allOne.inc("hello");
29 | allOne.getMaxKey(); // return "hello"
30 | allOne.getMinKey(); // return "hello"
31 | allOne.inc("leet");
32 | allOne.getMaxKey(); // return "hello"
33 | allOne.getMinKey(); // return "leet"
34 | 
35 | 36 |

 

37 |

Constraints:

38 | 39 |
    40 |
  • 1 <= key.length <= 10
  • 41 |
  • key consists of lowercase English letters.
  • 42 |
  • It is guaranteed that for each call to dec, key is existing in the data structure.
  • 43 |
  • At most 5 * 104 calls will be made to inc, dec, getMaxKey, and getMinKey.
  • 44 |
45 | -------------------------------------------------------------------------------- /3163-string-compression-iii/README.md: -------------------------------------------------------------------------------- 1 |

String Compression III

Difficulty: Medium

Given a string word, compress it using the following algorithm:

2 | 3 |
    4 |
  • Begin with an empty string comp. While word is not empty, use the following operation: 5 | 6 |
      7 |
    • Remove a maximum length prefix of word made of a single character c repeating at most 9 times.
    • 8 |
    • Append the length of the prefix followed by c to comp.
    • 9 |
    10 |
  • 11 |
12 | 13 |

Return the string comp.

14 | 15 |

 

16 |

Example 1:

17 | 18 |
19 |

Input: word = "abcde"

20 | 21 |

Output: "1a1b1c1d1e"

22 | 23 |

Explanation:

24 | 25 |

Initially, comp = "". Apply the operation 5 times, choosing "a", "b", "c", "d", and "e" as the prefix in each operation.

26 | 27 |

For each prefix, append "1" followed by the character to comp.

28 |
29 | 30 |

Example 2:

31 | 32 |
33 |

Input: word = "aaaaaaaaaaaaaabb"

34 | 35 |

Output: "9a5a2b"

36 | 37 |

Explanation:

38 | 39 |

Initially, comp = "". Apply the operation 3 times, choosing "aaaaaaaaa", "aaaaa", and "bb" as the prefix in each operation.

40 | 41 |
    42 |
  • For prefix "aaaaaaaaa", append "9" followed by "a" to comp.
  • 43 |
  • For prefix "aaaaa", append "5" followed by "a" to comp.
  • 44 |
  • For prefix "bb", append "2" followed by "b" to comp.
  • 45 |
46 |
47 | 48 |

 

49 |

Constraints:

50 | 51 |
    52 |
  • 1 <= word.length <= 2 * 105
  • 53 |
  • word consists only of lowercase English letters.
  • 54 |
55 | -------------------------------------------------------------------------------- /1894-find-the-student-that-will-replace-the-chalk/README.md: -------------------------------------------------------------------------------- 1 |

Find the Student that Will Replace the Chalk

Difficulty: Medium

There are n students in a class numbered from 0 to n - 1. The teacher will give each student a problem starting with the student number 0, then the student number 1, and so on until the teacher reaches the student number n - 1. After that, the teacher will restart the process, starting with the student number 0 again.

2 | 3 |

You are given a 0-indexed integer array chalk and an integer k. There are initially k pieces of chalk. When the student number i is given a problem to solve, they will use chalk[i] pieces of chalk to solve that problem. However, if the current number of chalk pieces is strictly less than chalk[i], then the student number i will be asked to replace the chalk.

4 | 5 |

Return the index of the student that will replace the chalk pieces.

6 | 7 |

 

8 |

Example 1:

9 | 10 |
11 | Input: chalk = [5,1,5], k = 22
12 | Output: 0
13 | Explanation: The students go in turns as follows:
14 | - Student number 0 uses 5 chalk, so k = 17.
15 | - Student number 1 uses 1 chalk, so k = 16.
16 | - Student number 2 uses 5 chalk, so k = 11.
17 | - Student number 0 uses 5 chalk, so k = 6.
18 | - Student number 1 uses 1 chalk, so k = 5.
19 | - Student number 2 uses 5 chalk, so k = 0.
20 | Student number 0 does not have enough chalk, so they will have to replace it.
21 | 22 |

Example 2:

23 | 24 |
25 | Input: chalk = [3,4,1,2], k = 25
26 | Output: 1
27 | Explanation: The students go in turns as follows:
28 | - Student number 0 uses 3 chalk so k = 22.
29 | - Student number 1 uses 4 chalk so k = 18.
30 | - Student number 2 uses 1 chalk so k = 17.
31 | - Student number 3 uses 2 chalk so k = 15.
32 | - Student number 0 uses 3 chalk so k = 12.
33 | - Student number 1 uses 4 chalk so k = 8.
34 | - Student number 2 uses 1 chalk so k = 7.
35 | - Student number 3 uses 2 chalk so k = 5.
36 | - Student number 0 uses 3 chalk so k = 2.
37 | Student number 1 does not have enough chalk, so they will have to replace it.
38 | 
39 | 40 |

 

41 |

Constraints:

42 | 43 |
    44 |
  • chalk.length == n
  • 45 |
  • 1 <= n <= 105
  • 46 |
  • 1 <= chalk[i] <= 105
  • 47 |
  • 1 <= k <= 109
  • 48 |
49 | -------------------------------------------------------------------------------- /1381-design-a-stack-with-increment-operation/README.md: -------------------------------------------------------------------------------- 1 |

Design a Stack With Increment Operation

Difficulty: Medium

Design a stack that supports increment operations on its elements.

2 | 3 |

Implement the CustomStack class:

4 | 5 |
    6 |
  • CustomStack(int maxSize) Initializes the object with maxSize which is the maximum number of elements in the stack.
  • 7 |
  • void push(int x) Adds x to the top of the stack if the stack has not reached the maxSize.
  • 8 |
  • int pop() Pops and returns the top of the stack or -1 if the stack is empty.
  • 9 |
  • void inc(int k, int val) Increments the bottom k elements of the stack by val. If there are less than k elements in the stack, increment all the elements in the stack.
  • 10 |
11 | 12 |

 

13 |

Example 1:

14 | 15 |
16 | Input
17 | ["CustomStack","push","push","pop","push","push","push","increment","increment","pop","pop","pop","pop"]
18 | [[3],[1],[2],[],[2],[3],[4],[5,100],[2,100],[],[],[],[]]
19 | Output
20 | [null,null,null,2,null,null,null,null,null,103,202,201,-1]
21 | Explanation
22 | CustomStack stk = new CustomStack(3); // Stack is Empty []
23 | stk.push(1);                          // stack becomes [1]
24 | stk.push(2);                          // stack becomes [1, 2]
25 | stk.pop();                            // return 2 --> Return top of the stack 2, stack becomes [1]
26 | stk.push(2);                          // stack becomes [1, 2]
27 | stk.push(3);                          // stack becomes [1, 2, 3]
28 | stk.push(4);                          // stack still [1, 2, 3], Do not add another elements as size is 4
29 | stk.increment(5, 100);                // stack becomes [101, 102, 103]
30 | stk.increment(2, 100);                // stack becomes [201, 202, 103]
31 | stk.pop();                            // return 103 --> Return top of the stack 103, stack becomes [201, 202]
32 | stk.pop();                            // return 202 --> Return top of the stack 202, stack becomes [201]
33 | stk.pop();                            // return 201 --> Return top of the stack 201, stack becomes []
34 | stk.pop();                            // return -1 --> Stack is empty return -1.
35 | 
36 | 37 |

 

38 |

Constraints:

39 | 40 |
    41 |
  • 1 <= maxSize, x, k <= 1000
  • 42 |
  • 0 <= val <= 100
  • 43 |
  • At most 1000 calls will be made to each method of increment, push and pop each separately.
  • 44 |
45 | -------------------------------------------------------------------------------- /2416-sum-of-prefix-scores-of-strings/README.md: -------------------------------------------------------------------------------- 1 |

Sum of Prefix Scores of Strings

Difficulty: Hard

You are given an array words of size n consisting of non-empty strings.

2 | 3 |

We define the score of a string word as the number of strings words[i] such that word is a prefix of words[i].

4 | 5 |
    6 |
  • For example, if words = ["a", "ab", "abc", "cab"], then the score of "ab" is 2, since "ab" is a prefix of both "ab" and "abc".
  • 7 |
8 | 9 |

Return an array answer of size n where answer[i] is the sum of scores of every non-empty prefix of words[i].

10 | 11 |

Note that a string is considered as a prefix of itself.

12 | 13 |

 

14 |

Example 1:

15 | 16 |
17 | Input: words = ["abc","ab","bc","b"]
18 | Output: [5,4,3,2]
19 | Explanation: The answer for each string is the following:
20 | - "abc" has 3 prefixes: "a", "ab", and "abc".
21 | - There are 2 strings with the prefix "a", 2 strings with the prefix "ab", and 1 string with the prefix "abc".
22 | The total is answer[0] = 2 + 2 + 1 = 5.
23 | - "ab" has 2 prefixes: "a" and "ab".
24 | - There are 2 strings with the prefix "a", and 2 strings with the prefix "ab".
25 | The total is answer[1] = 2 + 2 = 4.
26 | - "bc" has 2 prefixes: "b" and "bc".
27 | - There are 2 strings with the prefix "b", and 1 string with the prefix "bc".
28 | The total is answer[2] = 2 + 1 = 3.
29 | - "b" has 1 prefix: "b".
30 | - There are 2 strings with the prefix "b".
31 | The total is answer[3] = 2.
32 | 
33 | 34 |

Example 2:

35 | 36 |
37 | Input: words = ["abcd"]
38 | Output: [4]
39 | Explanation:
40 | "abcd" has 4 prefixes: "a", "ab", "abc", and "abcd".
41 | Each prefix has a score of one, so the total is answer[0] = 1 + 1 + 1 + 1 = 4.
42 | 
43 | 44 |

 

45 |

Constraints:

46 | 47 |
    48 |
  • 1 <= words.length <= 1000
  • 49 |
  • 1 <= words[i].length <= 1000
  • 50 |
  • words[i] consists of lowercase English letters.
  • 51 |
52 | -------------------------------------------------------------------------------- /scripts/node_modules/web-streams-polyfill/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web-streams-polyfill", 3 | "version": "3.3.3", 4 | "description": "Web Streams, based on the WHATWG spec reference implementation", 5 | "main": "dist/polyfill", 6 | "browser": "dist/polyfill.min.js", 7 | "module": "dist/polyfill.mjs", 8 | "types": "dist/types/polyfill.d.ts", 9 | "typesVersions": { 10 | ">=3.6": { 11 | "dist/types/*": [ 12 | "dist/types/ts3.6/*" 13 | ] 14 | } 15 | }, 16 | "scripts": { 17 | "test": "npm run test:types && npm run test:unit && npm run test:wpt", 18 | "test:wpt": "npm run test:wpt:node && npm run test:wpt:chromium && npm run test:wpt:firefox", 19 | "test:wpt:node": "node --expose_gc ./test/wpt/node/run.js", 20 | "test:wpt:chromium": "node ./test/wpt/browser/run.js --browser chromium", 21 | "test:wpt:firefox": "node ./test/wpt/browser/run.js --browser firefox", 22 | "test:types": "tsc -p ./test/types/tsconfig.json", 23 | "test:unit": "jasmine --config=test/unit/jasmine.json", 24 | "lint": "eslint \"src/**/*.ts\"", 25 | "build": "npm run build:bundle && npm run build:types", 26 | "build:bundle": "rollup -c", 27 | "build:types": "tsc --project . --emitDeclarationOnly --declarationDir ./lib && api-extractor run", 28 | "accept:types": "npm run build:types -- --local", 29 | "postbuild:types": "downlevel-dts ./dist/types/ts3.6/ ./dist/types/ --to=3.5 && node ./build/downlevel-dts.js", 30 | "prepare": "npm run build" 31 | }, 32 | "files": [ 33 | "dist", 34 | "es6", 35 | "es2018", 36 | "ponyfill" 37 | ], 38 | "engines": { 39 | "node": ">= 8" 40 | }, 41 | "repository": { 42 | "type": "git", 43 | "url": "git+https://github.com/MattiasBuelens/web-streams-polyfill.git" 44 | }, 45 | "keywords": [ 46 | "streams", 47 | "whatwg", 48 | "polyfill" 49 | ], 50 | "author": "Mattias Buelens ", 51 | "contributors": [ 52 | "Diwank Singh " 53 | ], 54 | "license": "MIT", 55 | "bugs": { 56 | "url": "https://github.com/MattiasBuelens/web-streams-polyfill/issues" 57 | }, 58 | "homepage": "https://github.com/MattiasBuelens/web-streams-polyfill#readme", 59 | "devDependencies": { 60 | "@microsoft/api-extractor": "^7.39.1", 61 | "@rollup/plugin-inject": "^5.0.5", 62 | "@rollup/plugin-replace": "^5.0.5", 63 | "@rollup/plugin-strip": "^3.0.4", 64 | "@rollup/plugin-terser": "^0.4.4", 65 | "@rollup/plugin-typescript": "^11.1.5", 66 | "@types/node": "^18.19.4", 67 | "@typescript-eslint/eslint-plugin": "^6.17.0", 68 | "@typescript-eslint/parser": "^6.17.0", 69 | "@ungap/promise-all-settled": "^1.1.2", 70 | "downlevel-dts": "^0.11.0", 71 | "eslint": "^8.56.0", 72 | "jasmine": "^5.1.0", 73 | "micromatch": "^4.0.5", 74 | "minimist": "^1.2.5", 75 | "playwright": "^1.14.1", 76 | "recursive-readdir": "^2.2.2", 77 | "rollup": "^4.9.2", 78 | "ts-morph": "^10.0.2", 79 | "tslib": "^2.6.2", 80 | "typescript": "^5.3.3", 81 | "wpt-runner": "^5.0.0" 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /scripts/node_modules/fetch-blob/from.js: -------------------------------------------------------------------------------- 1 | import { statSync, createReadStream, promises as fs } from 'node:fs' 2 | import { basename } from 'node:path' 3 | import DOMException from 'node-domexception' 4 | 5 | import File from './file.js' 6 | import Blob from './index.js' 7 | 8 | const { stat } = fs 9 | 10 | /** 11 | * @param {string} path filepath on the disk 12 | * @param {string} [type] mimetype to use 13 | */ 14 | const blobFromSync = (path, type) => fromBlob(statSync(path), path, type) 15 | 16 | /** 17 | * @param {string} path filepath on the disk 18 | * @param {string} [type] mimetype to use 19 | * @returns {Promise} 20 | */ 21 | const blobFrom = (path, type) => stat(path).then(stat => fromBlob(stat, path, type)) 22 | 23 | /** 24 | * @param {string} path filepath on the disk 25 | * @param {string} [type] mimetype to use 26 | * @returns {Promise} 27 | */ 28 | const fileFrom = (path, type) => stat(path).then(stat => fromFile(stat, path, type)) 29 | 30 | /** 31 | * @param {string} path filepath on the disk 32 | * @param {string} [type] mimetype to use 33 | */ 34 | const fileFromSync = (path, type) => fromFile(statSync(path), path, type) 35 | 36 | // @ts-ignore 37 | const fromBlob = (stat, path, type = '') => new Blob([new BlobDataItem({ 38 | path, 39 | size: stat.size, 40 | lastModified: stat.mtimeMs, 41 | start: 0 42 | })], { type }) 43 | 44 | // @ts-ignore 45 | const fromFile = (stat, path, type = '') => new File([new BlobDataItem({ 46 | path, 47 | size: stat.size, 48 | lastModified: stat.mtimeMs, 49 | start: 0 50 | })], basename(path), { type, lastModified: stat.mtimeMs }) 51 | 52 | /** 53 | * This is a blob backed up by a file on the disk 54 | * with minium requirement. Its wrapped around a Blob as a blobPart 55 | * so you have no direct access to this. 56 | * 57 | * @private 58 | */ 59 | class BlobDataItem { 60 | #path 61 | #start 62 | 63 | constructor (options) { 64 | this.#path = options.path 65 | this.#start = options.start 66 | this.size = options.size 67 | this.lastModified = options.lastModified 68 | } 69 | 70 | /** 71 | * Slicing arguments is first validated and formatted 72 | * to not be out of range by Blob.prototype.slice 73 | */ 74 | slice (start, end) { 75 | return new BlobDataItem({ 76 | path: this.#path, 77 | lastModified: this.lastModified, 78 | size: end - start, 79 | start: this.#start + start 80 | }) 81 | } 82 | 83 | async * stream () { 84 | const { mtimeMs } = await stat(this.#path) 85 | if (mtimeMs > this.lastModified) { 86 | throw new DOMException('The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.', 'NotReadableError') 87 | } 88 | yield * createReadStream(this.#path, { 89 | start: this.#start, 90 | end: this.#start + this.size - 1 91 | }) 92 | } 93 | 94 | get [Symbol.toStringTag] () { 95 | return 'Blob' 96 | } 97 | } 98 | 99 | export default blobFromSync 100 | export { File, Blob, blobFrom, blobFromSync, fileFrom, fileFromSync } 101 | -------------------------------------------------------------------------------- /641-design-circular-deque/README.md: -------------------------------------------------------------------------------- 1 |

Design Circular Deque

Difficulty: Medium

Design your implementation of the circular double-ended queue (deque).

2 | 3 |

Implement the MyCircularDeque class:

4 | 5 |
    6 |
  • MyCircularDeque(int k) Initializes the deque with a maximum size of k.
  • 7 |
  • boolean insertFront() Adds an item at the front of Deque. Returns true if the operation is successful, or false otherwise.
  • 8 |
  • boolean insertLast() Adds an item at the rear of Deque. Returns true if the operation is successful, or false otherwise.
  • 9 |
  • boolean deleteFront() Deletes an item from the front of Deque. Returns true if the operation is successful, or false otherwise.
  • 10 |
  • boolean deleteLast() Deletes an item from the rear of Deque. Returns true if the operation is successful, or false otherwise.
  • 11 |
  • int getFront() Returns the front item from the Deque. Returns -1 if the deque is empty.
  • 12 |
  • int getRear() Returns the last item from Deque. Returns -1 if the deque is empty.
  • 13 |
  • boolean isEmpty() Returns true if the deque is empty, or false otherwise.
  • 14 |
  • boolean isFull() Returns true if the deque is full, or false otherwise.
  • 15 |
16 | 17 |

 

18 |

Example 1:

19 | 20 |
21 | Input
22 | ["MyCircularDeque", "insertLast", "insertLast", "insertFront", "insertFront", "getRear", "isFull", "deleteLast", "insertFront", "getFront"]
23 | [[3], [1], [2], [3], [4], [], [], [], [4], []]
24 | Output
25 | [null, true, true, true, false, 2, true, true, true, 4]
26 | 
27 | Explanation
28 | MyCircularDeque myCircularDeque = new MyCircularDeque(3);
29 | myCircularDeque.insertLast(1);  // return True
30 | myCircularDeque.insertLast(2);  // return True
31 | myCircularDeque.insertFront(3); // return True
32 | myCircularDeque.insertFront(4); // return False, the queue is full.
33 | myCircularDeque.getRear();      // return 2
34 | myCircularDeque.isFull();       // return True
35 | myCircularDeque.deleteLast();   // return True
36 | myCircularDeque.insertFront(4); // return True
37 | myCircularDeque.getFront();     // return 4
38 | 
39 | 40 |

 

41 |

Constraints:

42 | 43 |
    44 |
  • 1 <= k <= 1000
  • 45 |
  • 0 <= value <= 1000
  • 46 |
  • At most 2000 calls will be made to insertFront, insertLast, deleteFront, deleteLast, getFront, getRear, isEmpty, isFull.
  • 47 |
48 | -------------------------------------------------------------------------------- /scripts/node_modules/data-uri-to-buffer/README.md: -------------------------------------------------------------------------------- 1 | data-uri-to-buffer 2 | ================== 3 | ### Generate a Buffer instance from a [Data URI][rfc] string 4 | [![Build Status](https://travis-ci.org/TooTallNate/node-data-uri-to-buffer.svg?branch=master)](https://travis-ci.org/TooTallNate/node-data-uri-to-buffer) 5 | 6 | This module accepts a ["data" URI][rfc] String of data, and returns a 7 | node.js `Buffer` instance with the decoded data. 8 | 9 | 10 | Installation 11 | ------------ 12 | 13 | Install with `npm`: 14 | 15 | ``` bash 16 | $ npm install data-uri-to-buffer 17 | ``` 18 | 19 | 20 | Example 21 | ------- 22 | 23 | ``` js 24 | import dataUriToBuffer from 'data-uri-to-buffer'; 25 | 26 | // plain-text data is supported 27 | let uri = 'data:,Hello%2C%20World!'; 28 | let decoded = dataUriToBuffer(uri); 29 | console.log(decoded.toString()); 30 | // 'Hello, World!' 31 | 32 | // base64-encoded data is supported 33 | uri = 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D'; 34 | decoded = dataUriToBuffer(uri); 35 | console.log(decoded.toString()); 36 | // 'Hello, World!' 37 | ``` 38 | 39 | 40 | API 41 | --- 42 | 43 | ### dataUriToBuffer(String uri) → Buffer 44 | 45 | The `type` property on the Buffer instance gets set to the main type portion of 46 | the "mediatype" portion of the "data" URI, or defaults to `"text/plain"` if not 47 | specified. 48 | 49 | The `typeFull` property on the Buffer instance gets set to the entire 50 | "mediatype" portion of the "data" URI (including all parameters), or defaults 51 | to `"text/plain;charset=US-ASCII"` if not specified. 52 | 53 | The `charset` property on the Buffer instance gets set to the Charset portion of 54 | the "mediatype" portion of the "data" URI, or defaults to `"US-ASCII"` if the 55 | entire type is not specified, or defaults to `""` otherwise. 56 | 57 | *Note*: If the only the main type is specified but not the charset, e.g. 58 | `"data:text/plain,abc"`, the charset is set to the empty string. The spec only 59 | defaults to US-ASCII as charset if the entire type is not specified. 60 | 61 | 62 | License 63 | ------- 64 | 65 | (The MIT License) 66 | 67 | Copyright (c) 2014 Nathan Rajlich <nathan@tootallnate.net> 68 | 69 | Permission is hereby granted, free of charge, to any person obtaining 70 | a copy of this software and associated documentation files (the 71 | 'Software'), to deal in the Software without restriction, including 72 | without limitation the rights to use, copy, modify, merge, publish, 73 | distribute, sublicense, and/or sell copies of the Software, and to 74 | permit persons to whom the Software is furnished to do so, subject to 75 | the following conditions: 76 | 77 | The above copyright notice and this permission notice shall be 78 | included in all copies or substantial portions of the Software. 79 | 80 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 81 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 82 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 83 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 84 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 85 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 86 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 87 | 88 | [rfc]: http://tools.ietf.org/html/rfc2397 89 | -------------------------------------------------------------------------------- /874-walking-robot-simulation/README.md: -------------------------------------------------------------------------------- 1 |

Walking Robot Simulation

Difficulty: Medium

A robot on an infinite XY-plane starts at point (0, 0) facing north. The robot can receive a sequence of these three possible types of commands:

2 | 3 |
    4 |
  • -2: Turn left 90 degrees.
  • 5 |
  • -1: Turn right 90 degrees.
  • 6 |
  • 1 <= k <= 9: Move forward k units, one unit at a time.
  • 7 |
8 | 9 |

Some of the grid squares are obstacles. The ith obstacle is at grid point obstacles[i] = (xi, yi). If the robot runs into an obstacle, then it will instead stay in its current location and move on to the next command.

10 | 11 |

Return the maximum Euclidean distance that the robot ever gets from the origin squared (i.e. if the distance is 5, return 25).

12 | 13 |

Note:

14 | 15 |
    16 |
  • North means +Y direction.
  • 17 |
  • East means +X direction.
  • 18 |
  • South means -Y direction.
  • 19 |
  • West means -X direction.
  • 20 |
  • There can be obstacle in [0,0].
  • 21 |
22 | 23 |

 

24 |

Example 1:

25 | 26 |
27 | Input: commands = [4,-1,3], obstacles = []
28 | Output: 25
29 | Explanation: The robot starts at (0, 0):
30 | 1. Move north 4 units to (0, 4).
31 | 2. Turn right.
32 | 3. Move east 3 units to (3, 4).
33 | The furthest point the robot ever gets from the origin is (3, 4), which squared is 32 + 42 = 25 units away.
34 | 
35 | 36 |

Example 2:

37 | 38 |
39 | Input: commands = [4,-1,4,-2,4], obstacles = [[2,4]]
40 | Output: 65
41 | Explanation: The robot starts at (0, 0):
42 | 1. Move north 4 units to (0, 4).
43 | 2. Turn right.
44 | 3. Move east 1 unit and get blocked by the obstacle at (2, 4), robot is at (1, 4).
45 | 4. Turn left.
46 | 5. Move north 4 units to (1, 8).
47 | The furthest point the robot ever gets from the origin is (1, 8), which squared is 12 + 82 = 65 units away.
48 | 
49 | 50 |

Example 3:

51 | 52 |
53 | Input: commands = [6,-1,-1,6], obstacles = []
54 | Output: 36
55 | Explanation: The robot starts at (0, 0):
56 | 1. Move north 6 units to (0, 6).
57 | 2. Turn right.
58 | 3. Turn right.
59 | 4. Move south 6 units to (0, 0).
60 | The furthest point the robot ever gets from the origin is (0, 6), which squared is 62 = 36 units away.
61 | 
62 | 63 |

 

64 |

Constraints:

65 | 66 |
    67 |
  • 1 <= commands.length <= 104
  • 68 |
  • commands[i] is either -2, -1, or an integer in the range [1, 9].
  • 69 |
  • 0 <= obstacles.length <= 104
  • 70 |
  • -3 * 104 <= xi, yi <= 3 * 104
  • 71 |
  • The answer is guaranteed to be less than 231.
  • 72 |
73 | -------------------------------------------------------------------------------- /scripts/node_modules/.package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scripts", 3 | "lockfileVersion": 3, 4 | "requires": true, 5 | "packages": { 6 | "node_modules/data-uri-to-buffer": { 7 | "version": "4.0.1", 8 | "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", 9 | "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", 10 | "license": "MIT", 11 | "engines": { 12 | "node": ">= 12" 13 | } 14 | }, 15 | "node_modules/fetch-blob": { 16 | "version": "3.2.0", 17 | "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", 18 | "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", 19 | "funding": [ 20 | { 21 | "type": "github", 22 | "url": "https://github.com/sponsors/jimmywarting" 23 | }, 24 | { 25 | "type": "paypal", 26 | "url": "https://paypal.me/jimmywarting" 27 | } 28 | ], 29 | "license": "MIT", 30 | "dependencies": { 31 | "node-domexception": "^1.0.0", 32 | "web-streams-polyfill": "^3.0.3" 33 | }, 34 | "engines": { 35 | "node": "^12.20 || >= 14.13" 36 | } 37 | }, 38 | "node_modules/formdata-polyfill": { 39 | "version": "4.0.10", 40 | "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", 41 | "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", 42 | "license": "MIT", 43 | "dependencies": { 44 | "fetch-blob": "^3.1.2" 45 | }, 46 | "engines": { 47 | "node": ">=12.20.0" 48 | } 49 | }, 50 | "node_modules/node-domexception": { 51 | "version": "1.0.0", 52 | "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", 53 | "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", 54 | "funding": [ 55 | { 56 | "type": "github", 57 | "url": "https://github.com/sponsors/jimmywarting" 58 | }, 59 | { 60 | "type": "github", 61 | "url": "https://paypal.me/jimmywarting" 62 | } 63 | ], 64 | "license": "MIT", 65 | "engines": { 66 | "node": ">=10.5.0" 67 | } 68 | }, 69 | "node_modules/node-fetch": { 70 | "version": "3.3.2", 71 | "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", 72 | "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", 73 | "license": "MIT", 74 | "dependencies": { 75 | "data-uri-to-buffer": "^4.0.0", 76 | "fetch-blob": "^3.1.4", 77 | "formdata-polyfill": "^4.0.10" 78 | }, 79 | "engines": { 80 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 81 | }, 82 | "funding": { 83 | "type": "opencollective", 84 | "url": "https://opencollective.com/node-fetch" 85 | } 86 | }, 87 | "node_modules/web-streams-polyfill": { 88 | "version": "3.3.3", 89 | "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", 90 | "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", 91 | "license": "MIT", 92 | "engines": { 93 | "node": ">= 8" 94 | } 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /scripts/node_modules/node-fetch/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-fetch", 3 | "version": "3.3.2", 4 | "description": "A light-weight module that brings Fetch API to node.js", 5 | "main": "./src/index.js", 6 | "sideEffects": false, 7 | "type": "module", 8 | "files": [ 9 | "src", 10 | "@types/index.d.ts" 11 | ], 12 | "types": "./@types/index.d.ts", 13 | "engines": { 14 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 15 | }, 16 | "scripts": { 17 | "test": "mocha", 18 | "coverage": "c8 report --reporter=text-lcov | coveralls", 19 | "test-types": "tsd", 20 | "lint": "xo" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "https://github.com/node-fetch/node-fetch.git" 25 | }, 26 | "keywords": [ 27 | "fetch", 28 | "http", 29 | "promise", 30 | "request", 31 | "curl", 32 | "wget", 33 | "xhr", 34 | "whatwg" 35 | ], 36 | "author": "David Frank", 37 | "license": "MIT", 38 | "bugs": { 39 | "url": "https://github.com/node-fetch/node-fetch/issues" 40 | }, 41 | "homepage": "https://github.com/node-fetch/node-fetch", 42 | "funding": { 43 | "type": "opencollective", 44 | "url": "https://opencollective.com/node-fetch" 45 | }, 46 | "devDependencies": { 47 | "abort-controller": "^3.0.0", 48 | "abortcontroller-polyfill": "^1.7.1", 49 | "busboy": "^1.4.0", 50 | "c8": "^7.7.2", 51 | "chai": "^4.3.4", 52 | "chai-as-promised": "^7.1.1", 53 | "chai-iterator": "^3.0.2", 54 | "chai-string": "^1.5.0", 55 | "coveralls": "^3.1.0", 56 | "form-data": "^4.0.0", 57 | "formdata-node": "^4.2.4", 58 | "mocha": "^9.1.3", 59 | "p-timeout": "^5.0.0", 60 | "stream-consumers": "^1.0.1", 61 | "tsd": "^0.14.0", 62 | "xo": "^0.39.1" 63 | }, 64 | "dependencies": { 65 | "data-uri-to-buffer": "^4.0.0", 66 | "fetch-blob": "^3.1.4", 67 | "formdata-polyfill": "^4.0.10" 68 | }, 69 | "tsd": { 70 | "cwd": "@types", 71 | "compilerOptions": { 72 | "esModuleInterop": true 73 | } 74 | }, 75 | "xo": { 76 | "envs": [ 77 | "node", 78 | "browser" 79 | ], 80 | "ignores": [ 81 | "example.js" 82 | ], 83 | "rules": { 84 | "complexity": 0, 85 | "import/extensions": 0, 86 | "import/no-useless-path-segments": 0, 87 | "import/no-anonymous-default-export": 0, 88 | "import/no-named-as-default": 0, 89 | "unicorn/import-index": 0, 90 | "unicorn/no-array-reduce": 0, 91 | "unicorn/prefer-node-protocol": 0, 92 | "unicorn/numeric-separators-style": 0, 93 | "unicorn/explicit-length-check": 0, 94 | "capitalized-comments": 0, 95 | "node/no-unsupported-features/es-syntax": 0, 96 | "@typescript-eslint/member-ordering": 0 97 | }, 98 | "overrides": [ 99 | { 100 | "files": "test/**/*.js", 101 | "envs": [ 102 | "node", 103 | "mocha" 104 | ], 105 | "rules": { 106 | "max-nested-callbacks": 0, 107 | "no-unused-expressions": 0, 108 | "no-warning-comments": 0, 109 | "new-cap": 0, 110 | "guard-for-in": 0, 111 | "unicorn/no-array-for-each": 0, 112 | "unicorn/prevent-abbreviations": 0, 113 | "promise/prefer-await-to-then": 0, 114 | "ava/no-import-test-files": 0 115 | } 116 | } 117 | ] 118 | }, 119 | "runkitExampleFilename": "example.js", 120 | "release": { 121 | "branches": [ 122 | "+([0-9]).x", 123 | "main", 124 | "next", 125 | { 126 | "name": "beta", 127 | "prerelease": true 128 | } 129 | ] 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /scripts/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "scripts", 3 | "lockfileVersion": 3, 4 | "requires": true, 5 | "packages": { 6 | "": { 7 | "dependencies": { 8 | "node-fetch": "^3.2.0" 9 | } 10 | }, 11 | "node_modules/data-uri-to-buffer": { 12 | "version": "4.0.1", 13 | "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", 14 | "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", 15 | "license": "MIT", 16 | "engines": { 17 | "node": ">= 12" 18 | } 19 | }, 20 | "node_modules/fetch-blob": { 21 | "version": "3.2.0", 22 | "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", 23 | "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", 24 | "funding": [ 25 | { 26 | "type": "github", 27 | "url": "https://github.com/sponsors/jimmywarting" 28 | }, 29 | { 30 | "type": "paypal", 31 | "url": "https://paypal.me/jimmywarting" 32 | } 33 | ], 34 | "license": "MIT", 35 | "dependencies": { 36 | "node-domexception": "^1.0.0", 37 | "web-streams-polyfill": "^3.0.3" 38 | }, 39 | "engines": { 40 | "node": "^12.20 || >= 14.13" 41 | } 42 | }, 43 | "node_modules/formdata-polyfill": { 44 | "version": "4.0.10", 45 | "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", 46 | "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", 47 | "license": "MIT", 48 | "dependencies": { 49 | "fetch-blob": "^3.1.2" 50 | }, 51 | "engines": { 52 | "node": ">=12.20.0" 53 | } 54 | }, 55 | "node_modules/node-domexception": { 56 | "version": "1.0.0", 57 | "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", 58 | "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", 59 | "funding": [ 60 | { 61 | "type": "github", 62 | "url": "https://github.com/sponsors/jimmywarting" 63 | }, 64 | { 65 | "type": "github", 66 | "url": "https://paypal.me/jimmywarting" 67 | } 68 | ], 69 | "license": "MIT", 70 | "engines": { 71 | "node": ">=10.5.0" 72 | } 73 | }, 74 | "node_modules/node-fetch": { 75 | "version": "3.3.2", 76 | "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", 77 | "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", 78 | "license": "MIT", 79 | "dependencies": { 80 | "data-uri-to-buffer": "^4.0.0", 81 | "fetch-blob": "^3.1.4", 82 | "formdata-polyfill": "^4.0.10" 83 | }, 84 | "engines": { 85 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 86 | }, 87 | "funding": { 88 | "type": "opencollective", 89 | "url": "https://opencollective.com/node-fetch" 90 | } 91 | }, 92 | "node_modules/web-streams-polyfill": { 93 | "version": "3.3.3", 94 | "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", 95 | "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", 96 | "license": "MIT", 97 | "engines": { 98 | "node": ">= 8" 99 | } 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /scripts/index.js: -------------------------------------------------------------------------------- 1 | import fetch from "node-fetch"; 2 | import fs from "fs"; 3 | import path from "path"; 4 | import { fileURLToPath } from "url"; 5 | 6 | const __filename = fileURLToPath(import.meta.url); 7 | const __dirname = path.dirname(__filename); 8 | 9 | const toc = async () => { 10 | // Fetch from API 11 | const data = await fetch( 12 | "https://api.github.com/repos/yashksaini-coder/September-Leetcode-Daily-2024/contents?ref=main" 13 | ) 14 | .then((response) => response.json()) 15 | .then((data) => data); 16 | 17 | var arr = Object.values(data); 18 | 19 | // Filter out the folders 20 | const folders = arr.filter( 21 | (item) => item.type === "dir" && item.name[0] !== "." 22 | ); 23 | 24 | // Make a table of contents 25 | var toc = []; 26 | folders.forEach((item) => { 27 | var num = parseInt(item.name.split("-")[0]); 28 | toc[num] = item.name; 29 | }); 30 | 31 | // Sort toc by key 32 | var sorted = Object.keys(toc) 33 | .sort() 34 | .reduce((obj, key) => { 35 | obj[key] = toc[key]; 36 | return obj; 37 | }, {}); 38 | 39 | // Generate the table of solutions 40 | let solutionsTable = ` 41 | 42 | | Leetcode Problem | Problem Statement | Solution | 43 | |---:|:-----|:----:| 44 | `; 45 | for (var key in sorted) { 46 | var str = sorted[key].split("-"); 47 | var name = str.slice(1).map(word => { 48 | const lowerCaseWord = word.toLowerCase(); 49 | if (["in", "of", "for", "and", "or", "the", "a", "an", "to", "by", "at", "from", "on", "off", "up", "down", "over", "under", "again", "further", "then", "once", "here", "there", "when", "where", "why", "how", "all", "any", "both", "each", "few", "more", "most", "other", "some", "such", "no", "nor", "not", "only", "own", "same", "so", "than", "too", "very", "s", "t", "can", "will", "just", "don", "should", "now"].includes(lowerCaseWord)) { 50 | return lowerCaseWord; 51 | } else if (lowerCaseWord.startsWith("i") && lowerCaseWord.length <= 3) { 52 | return lowerCaseWord.toUpperCase(); 53 | } else { 54 | return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(); 55 | } 56 | }).join(" "); 57 | name = name.charAt(0).toUpperCase() + name.slice(1); 58 | var num = key; 59 | var folderName = str.join("-"); 60 | var fileName = str.slice(1).join("-") + ".java"; 61 | var solutionPath = `./${folderName}/${fileName}`; 62 | solutionsTable += `| [${num}](https://leetcode.com/problems/${str.slice(1).join("-")}/) | ${name} | [Solution](${solutionPath}) |\n`; 63 | } 64 | solutionsTable += ""; 65 | 66 | // Read the existing README content 67 | const readmePath = path.join(__dirname, "..", "README.md"); 68 | let readmeContent = fs.readFileSync(readmePath, "utf8"); 69 | 70 | // Check if the solutions table already exists 71 | if (readmeContent.includes("")) { 72 | // Replace the existing table 73 | readmeContent = readmeContent.replace( 74 | /[\s\S]*/, 75 | solutionsTable 76 | ); 77 | } else { 78 | // Find the "## Solutions" heading and insert the table after it 79 | const solutionsHeading = "## Solutions"; 80 | const headingIndex = readmeContent.indexOf(solutionsHeading); 81 | if (headingIndex !== -1) { 82 | const insertIndex = headingIndex + solutionsHeading.length; 83 | readmeContent = readmeContent.slice(0, insertIndex) + "\n\n" + solutionsTable + readmeContent.slice(insertIndex); 84 | } else { 85 | console.error("Could not find '## Solutions' heading in README.md"); 86 | return; 87 | } 88 | } 89 | 90 | // Write the updated content back to README.md 91 | fs.writeFileSync(readmePath, readmeContent); 92 | console.log("README.md has been updated with the solutions table!"); 93 | }; 94 | 95 | toc(); -------------------------------------------------------------------------------- /scripts/node_modules/node-fetch/src/response.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Response.js 3 | * 4 | * Response class provides content decoding 5 | */ 6 | 7 | import Headers from './headers.js'; 8 | import Body, {clone, extractContentType} from './body.js'; 9 | import {isRedirect} from './utils/is-redirect.js'; 10 | 11 | const INTERNALS = Symbol('Response internals'); 12 | 13 | /** 14 | * Response class 15 | * 16 | * Ref: https://fetch.spec.whatwg.org/#response-class 17 | * 18 | * @param Stream body Readable stream 19 | * @param Object opts Response options 20 | * @return Void 21 | */ 22 | export default class Response extends Body { 23 | constructor(body = null, options = {}) { 24 | super(body, options); 25 | 26 | // eslint-disable-next-line no-eq-null, eqeqeq, no-negated-condition 27 | const status = options.status != null ? options.status : 200; 28 | 29 | const headers = new Headers(options.headers); 30 | 31 | if (body !== null && !headers.has('Content-Type')) { 32 | const contentType = extractContentType(body, this); 33 | if (contentType) { 34 | headers.append('Content-Type', contentType); 35 | } 36 | } 37 | 38 | this[INTERNALS] = { 39 | type: 'default', 40 | url: options.url, 41 | status, 42 | statusText: options.statusText || '', 43 | headers, 44 | counter: options.counter, 45 | highWaterMark: options.highWaterMark 46 | }; 47 | } 48 | 49 | get type() { 50 | return this[INTERNALS].type; 51 | } 52 | 53 | get url() { 54 | return this[INTERNALS].url || ''; 55 | } 56 | 57 | get status() { 58 | return this[INTERNALS].status; 59 | } 60 | 61 | /** 62 | * Convenience property representing if the request ended normally 63 | */ 64 | get ok() { 65 | return this[INTERNALS].status >= 200 && this[INTERNALS].status < 300; 66 | } 67 | 68 | get redirected() { 69 | return this[INTERNALS].counter > 0; 70 | } 71 | 72 | get statusText() { 73 | return this[INTERNALS].statusText; 74 | } 75 | 76 | get headers() { 77 | return this[INTERNALS].headers; 78 | } 79 | 80 | get highWaterMark() { 81 | return this[INTERNALS].highWaterMark; 82 | } 83 | 84 | /** 85 | * Clone this response 86 | * 87 | * @return Response 88 | */ 89 | clone() { 90 | return new Response(clone(this, this.highWaterMark), { 91 | type: this.type, 92 | url: this.url, 93 | status: this.status, 94 | statusText: this.statusText, 95 | headers: this.headers, 96 | ok: this.ok, 97 | redirected: this.redirected, 98 | size: this.size, 99 | highWaterMark: this.highWaterMark 100 | }); 101 | } 102 | 103 | /** 104 | * @param {string} url The URL that the new response is to originate from. 105 | * @param {number} status An optional status code for the response (e.g., 302.) 106 | * @returns {Response} A Response object. 107 | */ 108 | static redirect(url, status = 302) { 109 | if (!isRedirect(status)) { 110 | throw new RangeError('Failed to execute "redirect" on "response": Invalid status code'); 111 | } 112 | 113 | return new Response(null, { 114 | headers: { 115 | location: new URL(url).toString() 116 | }, 117 | status 118 | }); 119 | } 120 | 121 | static error() { 122 | const response = new Response(null, {status: 0, statusText: ''}); 123 | response[INTERNALS].type = 'error'; 124 | return response; 125 | } 126 | 127 | static json(data = undefined, init = {}) { 128 | const body = JSON.stringify(data); 129 | 130 | if (body === undefined) { 131 | throw new TypeError('data is not JSON serializable'); 132 | } 133 | 134 | const headers = new Headers(init && init.headers); 135 | 136 | if (!headers.has('content-type')) { 137 | headers.set('content-type', 'application/json'); 138 | } 139 | 140 | return new Response(body, { 141 | ...init, 142 | headers 143 | }); 144 | } 145 | 146 | get [Symbol.toStringTag]() { 147 | return 'Response'; 148 | } 149 | } 150 | 151 | Object.defineProperties(Response.prototype, { 152 | type: {enumerable: true}, 153 | url: {enumerable: true}, 154 | status: {enumerable: true}, 155 | ok: {enumerable: true}, 156 | redirected: {enumerable: true}, 157 | statusText: {enumerable: true}, 158 | headers: {enumerable: true}, 159 | clone: {enumerable: true} 160 | }); 161 | --------------------------------------------------------------------------------