1. String Permutationshistorical

    Given a string, print all permutations of its characters in lexicographic order. For example, given the string abc, print all strings formed by a, b, and c in lexicographic order: abc, acb, bac, bca, cab, and cba.

  2. Jump Floorhistorical

    A frog can jump either 1 step or 2 steps at a time. Find the total number of ways the frog can jump up a staircase with n steps (different orders count as different results).

  3. Jump Floor IIhistorical

    A frog can jump 1 step at a time, 2 steps at a time... or even n steps at a time. Find the total number of ways the frog can jump up a staircase with n steps.

  4. Fibonacci Sequencehistorical

    Given an integer n, output the nth item of the Fibonacci sequence (starting from 0, where the 0th item is 0 and the 1st item is 1).

  5. Number of 1 Bitshistorical

    Given an integer, output the number of 1s in its 32-bit binary representation. Negative numbers are represented using two's complement.

  6. Integer Power of a Numberhistorical

    Given a floating-point number base of type double and an integer exponent of type int, calculate base raised to the power of exponent.

  7. Number of Digit 1 Occurrenceshistorical

    Given an integer n, count how many times the digit 1 appears in all integers from 1 through n.

  8. First Non-Repeating Character in a Character Streamhistorical

    Implement a function that finds the first character that appears only once in a character stream. For example, after reading only the first two characters "go", the first character that appears once is "g".

  9. Left Rotate Stringhistorical

    Assembly language has a shift instruction called rotate left (ROL). This task uses a string to simulate its result. Given a character sequence S, output the sequence after cyclically rotating it K positions to the left.

  10. Poker Straighthistorical

    Determine whether five playing cards can form a straight, allowing jokers to represent any number.

  11. Replace Spaceshistorical

    Implement a function that replaces every space in a string with "%20". For example, when the string is We Are Happy., the result after replacement is We%20Are%20Happy.

  12. Print Linked List from Tail to Headhistorical

    Given a linked list, return an ArrayList containing its values from tail to head.

  13. Reverse Linked Listhistorical

    Given a linked list, reverse it and return the head of the reversed list.

  14. Merge Two Sorted Linked Listshistorical

    Given two monotonically increasing linked lists, merge them into one linked list that remains monotonically non-decreasing.

  15. K-th Node from the End of a Linked Listhistorical

    Given a linked list, return its k-th node from the end.

  16. Copy Complex Linked Listhistorical

    Given a complex linked list (each node contains a node value and two pointers, one pointing to the next node and another special pointer pointing to any node), return the head of the copied complex linked list.

  17. Entry Node of a Loop in a Linked Listhistorical

    Given a linked list, if it contains a cycle, find the entry node of the cycle; otherwise, return null.

  18. First Common Node of Two Linked Listshistorical

    Given two linked lists, find their first common node. (Note: because the input data is provided as linked lists, invalid test data may be displayed in other ways; the input data is guaranteed to be valid.).

  19. Delete Duplicate Nodes in a Linked Listhistorical

    In a sorted linked list, duplicate nodes may exist. Delete all duplicate nodes from the list without retaining any duplicate occurrence, and return the head pointer.

  20. Postorder Traversal Sequence of a Binary Search Treehistorical

    Given an integer array, determine whether it is the postorder traversal result of a binary search tree. Return true if it is, otherwise return false. Assume that any two numbers in the input array are distinct.

  21. Next Node in a Binary Treehistorical

    Given a binary tree and one of its nodes, find and return the next node in inorder traversal order. Note that each tree node contains not only left and right child pointers, but also a pointer to its parent.

  22. Binary Search Tree and Doubly Linked Listhistorical

    Given a binary search tree, convert it into a sorted doubly linked list. No new nodes may be created; only the pointers between existing tree nodes may be adjusted.

  23. Kth Node in a Binary Search Treehistorical

    Given a binary search tree, find its kth smallest node. For example, in (5, 3, 7, 2, 4, 6, 8), the value of the third smallest node is 4.

  24. Depth of a Binary Treehistorical

    Given a binary tree, find its depth. A path is formed by the nodes traversed from the root to a leaf, including both the root and the leaf. The length of the longest path is the depth of the tree.

  25. Print a Binary Tree from Top to Bottomhistorical

    Print every node of a binary tree from top to bottom, with nodes on the same level printed from left to right.

  26. Symmetric Binary Treehistorical

    Implement a function to determine whether a binary tree is symmetric. A binary tree is defined as symmetric if it is identical to its mirror image.

  27. Balanced Binary Treehistorical

    Given a binary tree, determine whether it is a balanced binary tree.

  28. Mirror of a Binary Treehistorical

    Transform a binary tree into its mirror by swapping the left and right subtrees at every node.

  29. Print a Binary Tree in Multiple Lineshistorical

    Print a binary tree level by level from top to bottom, with nodes on the same level output from left to right. Output each level on a separate line.

  30. Print a Binary Tree in Zigzag Orderhistorical

    Implement a function that prints a binary tree in zigzag order: the first row from left to right, the second level from right to left, the third row from left to right, and so on.

  31. Substructure of a Treehistorical

    Given two binary trees A and B, determine whether B is a substructure of A. (ps: an empty tree is not considered a substructure of any tree.).

  32. Reconstruct Binary Treehistorical

    Given the preorder traversal and inorder traversal results of a binary tree, reconstruct the binary tree. Assume that the input preorder traversal and inorder traversal results contain no duplicate numbers.

  33. Paths in a Binary Tree With a Given Sumhistorical

    Given the root node of a binary tree and an integer, print all paths in the binary tree whose node values sum to the given integer. A path is defined as the nodes traversed from the root node of the tree downward to a leaf node.

  34. Serialize a Binary Treehistorical

    Implement two functions to serialize and deserialize a binary tree respectively.

  35. Convert a String to an Integerhistorical

    Convert a string to an integer without using a library function that converts strings to integers. Return 0 if the value is 0 or if the string is not a valid numeric value.

  36. Reverse Word Orderhistorical

    Reverse the order of words in an English sentence while preserving the character order within each word.

  37. Stack with a min Functionhistorical

    Define a stack data structure and implement a min function in this type that can obtain the minimum element contained in the stack, with O(1) time complexity.

  38. Stack Push and Pop Sequenceshistorical

    Given two integer sequences, the first sequence represents the push order of a stack. Determine whether the second sequence could be a pop order of that stack.

  39. Implement a Queue with Two Stackshistorical

    Use two stacks to implement a queue and complete the queue's Push and Pop operations. The elements in the queue are of type int.

  40. Search in a 2D Arrayhistorical

    Each row and column of a two-dimensional array is sorted in ascending order. Determine whether a given integer appears in the array.

  41. Two Numbers with Sum Shistorical

    Given an array sorted in increasing order and a number S, find two numbers in the array whose sum is exactly S. If there are multiple pairs whose sum equals S, output the pair with the smallest product.

  42. Continuous Positive Sequences with Sum Shistorical

    Given a positive integer S, find all sequences of at least two consecutive positive integers whose sum is S.

  43. Last Remaining Number in a Circlehistorical

    Arrange n numbers in a circle and repeatedly remove every m-th number. Find the last remaining number.

  44. Arrange an Array into the Smallest Numberhistorical

    Given an array of positive integers, concatenate all numbers to form one number and print the smallest possible result. For example, for {3,32,321}, the smallest number that can be formed is 321323.

  45. Count Occurrences in a Sorted Arrayhistorical

    Count how many times a number appears in a sorted array.

  46. Number Appearing More Than Half the Timehistorical

    An array contains a number that appears more than half the length of the array. Find this number. For example, in the length-9 array {1,2,3,2,2,2,5,4,2}, the number 2 appears five times, which is more than half the array length, so output 2.

  47. Numbers Appearing Only Oncehistorical

    In an integer array, every number appears twice except for two numbers. Write a program to find the two numbers that appear only once.

  48. Inverse Pairs in an Arrayhistorical

    An inversion occurs when an earlier array element is greater than a later one. Count all inversions in the given array.

  49. Duplicate Number in an Arrayhistorical

    An array of length n contains values from 0 to n - 1, with some values repeated. Find a duplicate value.

  50. Minimum Number in a Rotated Arrayhistorical

    Moving some elements from the beginning of an array to the end is called a rotation of the array. Given a rotation of a non-decreasingly sorted array, output the minimum element of the rotated array.

  51. Smallest K Numbershistorical

    Given n integers, find the smallest K numbers. For example, among 4,5,1,6,2,7,3,8, the smallest four numbers are 1,2,3,4.

  52. Robot Movement Rangehistorical

    There is a grid with m rows and n columns. A robot starts at coordinate (0,0) and can move one cell at a time left, right, up, or down, but it cannot enter a cell when the sum of the digits of its row and column coordinates is greater than k.

  53. Maximum in Sliding Windowshistorical

    Given an array and a sliding-window size, find the maximum value in every sliding window. For example, for the array {2,3,4,2,6,2,5,1} with window size 3, there are six windows and their maximum values are {4,4,6,6,6,5}.

  54. Reorder Array with Odd Numbers Before Even Numbershistorical

    Given an integer array, implement a function that reorders its numbers so that all odd numbers are in the first half and all even numbers are in the second half, while preserving the relative order among odd numbers and among even numbers.

  55. Maximum Sum of a Contiguous Subarrayhistorical

    Given an integer array that may contain negative values, find the maximum sum of a contiguous subarray.