Apply Transform Over Each Element in Array Problem

Problem Given an integer array arr and a mapping function fn, return a new array with a transformation applied to each element. The returned array should be created such that returnedArray[i] = fn(arr[i], i). Please solve it without the built-in Array.map method. Examples Example 1: Input: arr = [1,2,3], fn = function plusone(n) { return n + 1; } Output: [2,3,4] Explanation: const newArray = map(arr, plusone); // [2,3,4] The function increases each value in the array by one. ...

Crawler Log Folder Problem

Problem The Leetcode file system keeps a log each time some user performs a change folder operation. The operations are described below: "../" : Move to the parent folder of the current folder. (If you are already in the main folder, remain in the same folder). "./" : Remain in the same folder. "x/" : Move to the child folder named x (This folder is guaranteed to always exist). You are given a list of strings logs where logs[i] is the operation performed by the user at the ith step. ...

Island Perimeter Problem

Island Perimeter Problem Problem You are given row x col grid representing a map where grid[i][j] = 1 represents land and grid[i][j] = 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely surrounded by water, and there is exactly one island (i.e., one or more connected land cells). The island doesn’t have “lakes”, meaning the water inside isn’t connected to the water around the island. One cell is a square with side length 1. The grid is rectangular, width and height don’t exceed 100. Determine the perimeter of the island. ...

Valid Word Square Problem

Problem Given a sequence of words, check whether it forms a valid word square. A sequence of words forms a valid word square if the k_th row and column read the exact same string, where 0 ≤ k < max(numRows, numColumns). Note: Examples Example 1: $$ \begin{bmatrix} \color{red} a & \color{red} b & \color{red} c & \color{red} d \\ \color{red} b & \color{green} n & \color{green} r & \color{green} t \\ \color{red} c & \color{green} r & \color{blue} m & \color{blue} y \\ \color{red} d & \color{green} t & \color{blue} y & \color{violet} e \end{bmatrix} $$ ...

Add Strings Problem

Problem Given two non-negative integers, num1 and num2 represented as string, return the sum of num1 and num2 as a string. You must solve the problem without using any built-in library for handling large integers (such as BigInteger). You must also not convert the inputs to integers directly. Examples Example 1: Input: num1 = "11", num2 = "123" Output: "134" ...

Convert Number to Hexadecimal Number Problem

Convert Number to Hexadecimal Number Problem Problem Given an integer num, return a string representing its hexadecimal representation. For negative integers, two’s complement method is used. All the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer except for the zero itself. Note: You are not allowed to use any built-in library method to directly solve this problem. ...

Binary Watch Problem

Binary Watch Problem Problem A binary watch has 4 LEDs on the top to represent the hours (0-11), and 6 LEDs on the bottom to represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right. For example, the below binary watch reads "4:51". ...

Leaf-Similar Trees Problem

Problem Consider all the leaves of a binary tree, from left to right order, the values of those leaves form a leaf value sequence. graph TD; A(3) --- B(5) & C(1) B --- D(6) & E(2) E --- F(7) & G(4) C --- H(9) & I(8) style D fill:#4682B4,stroke:#333,stroke-width:2px style F fill:#4682B4,stroke:#333,stroke-width:2px style G fill:#4682B4,stroke:#333,stroke-width:2px style H fill:#4682B4,stroke:#333,stroke-width:2px style I fill:#4682B4,stroke:#333,stroke-width:2px ...

Add to Array-Form of Integer Problem

Problem The array-form of an integer num is an array representing its digits in left to right order. For example, for num = 1321, the array form is [1,3,2,1]. Given num, the array-form of an integer, and an integer k, return the array-form of the integer num + k. Examples Example 1: Input: num = [1,2,0,0], k = 34 Output: [1,2,3,4] Explanation: 1200 + 34 = 1234 ...

N-ary Tree Postorder Traversal Problem

Problem Given the root of an n-ary tree, return the postorder traversal of its nodes’ values. Nary-Tree input serialization is represented in their level order traversal. Each group of children is separated by the null value (See examples) Examples Example 1: graph TD 1 --- A[3] & B[2] & C[4] A --- 5 & 6 (have to use A, B, C in mermaid to make the ordering of nodes better) ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy