[AtCoder] C - Monsters Battle RoyaleRead more
[Codeforces] Round #167 (Div. 2) B. Dima and SequenceRead more
[Codeforces] Round #170 (Div. 1) A. Learning LanguagesRead more
[Codeforces] Round #171 (Div. 2) A. Point on SpiralRead more
[Codeforces] Round #171 (Div. 2) B. BooksRead more
[Codeforces] Round #174 (Div. 2) A. Cows and Primitive RootsRead more
[LeetCode] Longest Cycle in a Graph

2360. Longest Cycle in a Graph

You are given a directed graph of n nodes numbered from 0 to n - 1, where each node has at most one outgoing edge.

The graph is represented with a given 0-indexed array edges of size n, indicating that there is a directed edge from node i to node edges[i]. If there is no outgoing edge from node i, then edges[i] == -1.

Return the length of the longest cycle in the graph. If no cycle exists, return -1.

A cycle is a path that starts and ends at the same node.

Read more
[LeetCode] Find Closest Node to Given Two Nodes

2359. Find Closest Node to Given Two Nodes

You are given a directed graph of n nodes numbered from 0 to n - 1, where each node has at most one outgoing edge.

The graph is represented with a given 0-indexed array edges of size n, indicating that there is a directed edge from node i to node edges[i]. If there is no outgoing edge from i, then edges[i] == -1.

You are also given two integers node1 and node2.

Return the index of the node that can be reached from both node1 and node2, such that the maximum between the distance from node1 to that node, and from node2 to that node is minimized. If there are multiple answers, return the node with the smallest index, and if no possible answer exists, return -1.

Note that edges may contain cycles.

Read more
[LeetCode] Maximum Number of Groups Entering a Competition

2358. Maximum Number of Groups Entering a Competition

You are given a positive integer array grades which represents the grades of students in a university. You would like to enter all these students into a competition in ordered non-empty groups, such that the ordering meets the following conditions:

  • The sum of the grades of students in the ith group is less than the sum of the grades of students in the (i + 1)th group, for all groups (except the last).
  • The total number of students in the ith group is less than the total number of students in the (i + 1)th group, for all groups (except the last).

Return the maximum number of groups that can be formed

Read more
[LeetCode] Make Array Zero by Subtracting Equal Amounts

2357. Make Array Zero by Subtracting Equal Amounts

You are given a non-negative integer array nums. In one operation, you must:

  • Choose a positive integer x such that x is less than or equal to the smallest non-zero element in nums.
  • Subtract x from every positive element in nums.

Return the minimum number of operations to make every element in nums equal to 0.

Read more