Skip to content
Discussion options

You must be logged in to vote

We need to determine the number of potions that form a successful pair with each spell. A successful pair is defined as a spell and potion whose product of strengths is at least a given success value. Given the constraints, a brute-force approach would be inefficient, so we use sorting and binary search to optimize the solution.

Approach

  1. Sort the Potions Array: Sorting the potions array allows us to efficiently find the minimum potion strength required for a successful pair with each spell using binary search.
  2. Binary Search for Each Spell: For each spell, calculate the minimum potion strength required to form a successful pair. This is done by computing the ceiling of success / spell_str…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Oct 8, 2025
Maintainer Author

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Oct 8, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants