π¨βπ»
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isIsomorphic = function(s, t) { | |
// Create two empty objects to store the mapping of characters | |
var mapS = {}; | |
var mapT = {}; | |
// Iterate over the length of the first string | |
for (var i = 0; i < s.length; i++) { | |
// If the character in s doesn't exist in mapS, add it | |
if (!mapS[s[i]]) { | |
mapS[s[i]] = t[i]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var exist = function(board, word) { | |
const dfs = (i, j, k) => { | |
// Base case: If k reaches the end of the word, return True | |
if (k === word.length) { | |
return true; | |
} | |
// Check if the current cell is out of bounds or does not match the word | |
if ( | |
i < 0 || | |
i >= board.length || |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var makeGood = function(s) { | |
// Create a stack to keep of the characters | |
let stack = []; | |
// Iterate over each character in the string | |
for (let i = 0; i < s.length; i++) { | |
// If the stack is not empty and the current character is the opposite case of the last character in the stack | |
if (stack.length > 0 && Math.abs(s.charCodeAt(i) - stack[stack.length - 1].charCodeAt(0)) === 32) { | |
// Remove the last character from the stack | |
stack.pop(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var minRemoveToMakeValid = function(s) { | |
// Convert the string to an array to facilitate removal of characters | |
let chars = s.split(''); | |
// Stack to keep track of indices of opening parentheses | |
let stack = []; | |
// Iterate through the characters of the string | |
for (let i = 0; i < chars.length; i++) { | |
// If the character is an opening parenthesis, add its index to the stack |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number[]} tickets | |
* @param {number} k | |
* @return {number} | |
*/ | |
var timeRequiredToBuy = function(tickets, k) { | |
// Initialize a counter to keep track of the total time | |
let count = 0; | |
// Loop through the tickets array in a circular manner |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {character[][]} matrix | |
* @return {number} | |
*/ | |
var maximalRectangle = function(matrix) { | |
if (matrix.length === 0) return 0; // If the matrix is empty, return 0 | |
var m = matrix.length; | |
var n = matrix[0].length; | |
var left = new Array(n).fill(0); // Initialize left, right and height arrays |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* function TreeNode(val, left, right) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.left = (left===undefined ? null : left) | |
* this.right = (right===undefined ? null : right) | |
* } | |
*/ | |
/** | |
* @param {TreeNode} root |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number[][]} grid | |
* @return {number} | |
*/ | |
var islandPerimeter = function(grid) { | |
// Initialize perimeter to 0 | |
var perimeter = 0; | |
// Loop through each cell in the grid | |
for (var i = 0; i < grid.length; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for singly-linked list. | |
* function ListNode(val, next) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.next = (next===undefined ? null : next) | |
* } | |
*/ | |
/** | |
* @param {ListNode} head | |
* @return {ListNode} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number[]} arr | |
* @param {number} k | |
* @return {number[]} | |
*/ | |
// Define the function that takes an array and a number k as input | |
var kthSmallestPrimeFraction = function(arr, k) { | |
// Initialize a new max priority queue | |
let newarr = new MaxPriorityQueue(); | |
OlderNewer