All Posts

Leetcode 382: Linked List Random Node

Given a singly linked list, implement a class that supports the initialization of the list and the ability to return a random node’s value with equal probability.

Leetcode 384: Shuffle an Array

You are given an integer array nums. Design an algorithm to randomly shuffle the array. All permutations of the array should be equally likely as a result of the shuffling.

Leetcode 385: Mini Parser

Given a string s representing a serialized nested list, implement a parser to deserialize it and return the deserialized NestedInteger.

Leetcode 386: Lexicographical Numbers

Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order. The solution must run in O(n) time and use O(1) extra space.

Leetcode 388: Longest Absolute File Path

In a file system where both directories and files are stored, we are given a string representation of the system. The string includes the directory structure, with tab characters (’\t’) representing subdirectories and newline characters (’\n’) representing file and directory boundaries. Each directory and file has a unique absolute path. Compute the length of the longest absolute path to a file. If no file exists, return 0.

Leetcode 390: Elimination Game

Given an integer n, simulate a process on a list of integers from 1 to n where every other number is removed, alternating the direction from left to right and right to left until only one number remains. Return the last remaining number.