[AtCoder] C - Cat Snuke and a VoyageRead more
[AtCoder] D - Grid ColoringRead more
[AtCoder] C - 4-adjacentRead more
[Codeforces] Round #724 (Div. 2) C. Diluc and KaeyaRead more
[Codeforces] Round #725 (Div. 3) F. Interesting FunctionRead more
[Codeforces] Plus and MultiplyRead more
[Codeforces] Round #732 (Div. 1) A. AquaMoon and Strange SortRead more
[Codeforces] Round #731 (Div. 3) E. Air ConditionersRead more
[LeetCode] Depth of BST Given Insertion Order

1902. Depth of BST Given Insertion Order

You are given a 0-indexed integer array order of length n, a permutation of integers from 1 to n representing the order of insertion into a binary search tree.

A binary search tree is defined as follows:

  • The left subtree of a node contains only nodes with keys less than the node’s key.
  • The right subtree of a node contains only nodes with keys greater than the node’s key.
  • Both the left and right subtrees must also be binary search trees.

The binary search tree is constructed as follows:

  • order[0] will be the root of the binary search tree.
  • All subsequent elements are inserted as the child of any existing node such that the binary search tree properties hold.

Return the depth of the binary search tree.

A binary tree’s depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

Read more
[LeetCode] Game of Nim

1908. Game of Nim

Alice and Bob take turns playing a game with Alice starting first.

In this game, there are n piles of stones. On each player’s turn, the player should remove any positive number of stones from a non-empty pile of his or her choice. The first player who cannot make a move loses, and the other player wins.

Given an integer array piles, where piles[i] is the number of stones in the ith pile, return true if Alice wins, or false if Bob wins.

Both Alice and Bob play optimally.

Read more