[Codeforces] Educational Round 52 (Rated for Div. 2) C. Make It EqualRead more
[Codeforces] Round #521 (Div. 3) D. Cutting OutRead more
[Codeforces] Educational Round 55 (Rated for Div. 2) B. Vova and TrophiesRead more
[Codeforces] Educational Round 55 (Rated for Div. 2) C. Multi-Subject CompetitionRead more
[Codeforces] Technocup 2019 - Elimination Round 4 C. Connect ThreeRead more
[LeetCode] Number of Unequal Triplets in Array

2475. Number of Unequal Triplets in Array

You are given a 0-indexed array of positive integers nums. Find the number of triplets (i, j, k) that meet the following conditions:

  • 0 <= i < j < k < nums.length
  • nums[i], nums[j], and nums[k] are pairwise distinct.
  • In other words, nums[i] != nums[j], nums[i] != nums[k], and nums[j] != nums[k].

Return the number of triplets that meet the conditions.

Read more
[LeetCode] Closest Nodes Queries in a Binary Search Tree

2476. Closest Nodes Queries in a Binary Search Tree

You are given the root of a binary search tree and an array queries of size n consisting of positive integers.

Find a 2D array answer of size n where answer[i] = [mini, maxi]:

  • mini is the largest value in the tree that is smaller than or equal to queries[i]. If a such value does not exist, add -1 instead.
  • maxi is the smallest value in the tree that is greater than or equal to queries[i]. If a such value does not exist, add -1 instead.

Return the array answer.

Read more
[LeetCode] Minimum Fuel Cost to Report to the Capital

2477. Minimum Fuel Cost to Report to the Capital

There is a tree (i.e., a connected, undirected graph with no cycles) structure country network consisting of n cities numbered from 0 to n - 1 and exactly n - 1 roads. The capital city is city 0. You are given a 2D integer array roads where roads[i] = [ai, bi] denotes that there exists a bidirectional road connecting cities ai and bi.

There is a meeting for the representatives of each city. The meeting is in the capital city.

There is a car in each city. You are given an integer seats that indicates the number of seats in each car.

A representative can use the car in their city to travel or change the car and ride with another representative. The cost of traveling between two cities is one liter of fuel.

Return the minimum number of liters of fuel to reach the capital city.

Read more
[LeetCode] Number of Beautiful Partitions

2478. Number of Beautiful Partitions

You are given a string s that consists of the digits ‘1’ to ‘9’ and two integers k and minLength.

A partition of s is called beautiful if:

  • s is partitioned into k non-intersecting substrings.
  • Each substring has a length of at least minLength.
  • Each substring starts with a prime digit and ends with a non-prime digit. Prime digits are ‘2’, ‘3’, ‘5’, and ‘7’, and the rest of the digits are non-prime.

Return the number of beautiful partitions of s. Since the answer may be very large, return it modulo 109 + 7.

A substring is a contiguous sequence of characters within a string.

Read more
[CodeChef] Pairwise union of setsRead more